如何在angular2中格式化日期?

Tra*_*ker 3 date angular

我的代码:

   this.nextDay = new Date();
   var datePipe = new DatePipe('en-US')
   this.presentDate = datePipe.transform(this.nextDay, 'YYYY-MM-DD H:mm:ss');
Run Code Online (Sandbox Code Playgroud)

但是通过上面的代码,我得到了 this.presentDate = yyyy-3-DD 23:04:99

我想约会2017-3-23 23:09:06,但在这里我不知道为什么我得到了yyyy?

dri*_*max 5

您需要使用单个y和小写dd

this.nextDay = new Date();
var datePipe = new DatePipe('en-US')
this.presentDate = datePipe.transform(this.nextDay, 'y-MM-dd H:mm:ss');
Run Code Online (Sandbox Code Playgroud)

参考:https://webdev.dartlang.org/angular/api/angular2.common/DatePipe-class