Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why angular date pipe will minus one day?

Tags:

date

angular

pipe

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?

like image 426
WenliL Avatar asked Jun 30 '26 20:06

WenliL


1 Answers

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"}}
like image 153
GeertPt Avatar answered Jul 03 '26 11:07

GeertPt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!