[英]Angular 4 input type date format
在项目编辑选项中,我有一个这样的表格。如何将日期格式更改为dd / MM / yy。例如07/07/18但反映为整年。如何覆盖此格式?
<input type="date" class="form-control" name="published" #published [(ngModel)] = "books.published" [ngModelOptions]="{ standalone: true }"/>
Set the value returned by the below fiddler function to your model and bind it to your view. 将下面的提琴手函数返回的值设置为模型,并将其绑定到视图。 jsfiddle
的jsfiddle
//A function for formatting a date to MM/dd/yy
function formatDate(d)
{
//get the month
var month = d.getMonth();
//get the day
//convert day to string
var day = d.getDate().toString();
//get the year
var year = d.getFullYear();
//pull the last two digits of the year
year = year.toString().substr(-2);
//increment month by 1 since it is 0 indexed
//converts month to a string
month = (month + 1).toString();
//if month is 1-9 pad right with a 0 for two digits
if (month.length === 1)
{
month = "0" + month;
}
//if day is between 1-9 pad right with a 0 for two digits
if (day.length === 1)
{
day = "0" + day;
}
//return the string "MMddyy"
return month +'/'+ day +'/'+ year;
}
var d = new Date();
alert(formatDate(d));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.