Home > other >  Why angular date pipe will minus one day?
Why angular date pipe will minus one day?

Time:09-17

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?

CodePudding user response:

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"}}
  • Related