Francesco Giberti
Francesco Giberti

Reputation: 95

Convert Date "Tue Sep 25 2018" in "dd-mm-yyyy" [angular4]

Im trying to convert the Date in the "dd-mm-yyyy" format with no success.

Ive tried to use this.datePipe.transform(this.filter.offerExpiration,"yyyy-MM-dd") but it doesnt work (the date doesnt change at all).

What can I do?

Thank you for the help.

Upvotes: 1

Views: 276

Answers (1)

Maximilian C.
Maximilian C.

Reputation: 967

If you use the following code, your date will not change:

this.datePipe.transform(this.filter.offerExpiration,"yyyy-MM-dd");
console.log(this.filter.offerExpiration);

The datePipe returns the modified date. This should do the trick:

let formattedDate = this.datePipe.transform(this.filter.offerExpiration,"yyyy-MM-dd");
console.log(formattedDate);

Upvotes: 3

Related Questions