1

If I use {{"2021-09-30T00:00:00Z" | date: "yyyy-MM-dd"}}, it will automatically minus one day and show 2021-09-29. I think it is because the time is 00:00, which make it confused?

How I can make the date correct as showing 2021-09-30 using date pipe in angular?

WenliL
  • 419
  • 2
  • 14

1 Answers1

5

You added a Z at the end, which means it's interpreted as in the UTC (GMT) timezone.

If you're in a GMT-XX timezone, that's the previous day.

Try dropping the Z to have a timestamp at midnight in your local time zone.

Or alternatively, use UTC in your date formatter:

{{"2021-09-30T00:00:00Z" | date: "yyyy-MM-dd":"UTC"}}
GeertPt
  • 16,398
  • 2
  • 37
  • 61