How to format date in angular2?
My code:
this.nextDay = new Date();
var datePipe = new DatePipe('en-US')
this.presentDate = datePipe.transform(this.nextDay, 'YYYY-MM-DD H:mm:ss');
But with the above code I am getting this.presentDate = yyyy-3-DD 23:04:99
I need a date like 2017-3-23 23:09:06 but here I don't know why I got yyyy ?.
+3
source to share
1 answer
You need to use one y
and lowercasedd
this.nextDay = new Date();
var datePipe = new DatePipe('en-US')
this.presentDate = datePipe.transform(this.nextDay, 'y-MM-dd H:mm:ss');
Link: https://webdev.dartlang.org/angular/api/angular2.common/DatePipe-class
+5
source to share