Date 如何在angular2中格式化日期?
我的代码:Date 如何在angular2中格式化日期?,date,angular,Date,Angular,我的代码: this.nextDay = new Date(); var datePipe = new DatePipe('en-US') this.presentDate = datePipe.transform(this.nextDay, 'YYYY-MM-DD H:mm:ss'); 但是通过上面的代码,我得到了this.presentDate=yyyy-3-DD 23:04:99 我希望日期为2017-3-23 23:09:06,但我不知道为什么我得到了yyyy?您需要
this.nextDay = new Date();
var datePipe = new DatePipe('en-US')
this.presentDate = datePipe.transform(this.nextDay, 'YYYY-MM-DD H:mm:ss');
但是通过上面的代码,我得到了this.presentDate=yyyy-3-DD 23:04:99
我希望日期为2017-3-23 23:09:06,但我不知道为什么我得到了yyyy?您需要使用单个
y
和小写dd
this.nextDay = new Date();
var datePipe = new DatePipe('en-US')
this.presentDate = datePipe.transform(this.nextDay, 'y-MM-dd H:mm:ss');
参考: