3

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 want date as 2017-3-23 23:09:06 ,but here I don't know why I got yyyy?.

1 Answer 1

5

You need to use a single y and lowercase dd

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.