I have a date string, like this 1987-06-15T00:00:00.000Z
, when I am added date pipe on it the date is showing a different date like Jun 14, 1987
in American time zone, but in India, it's showing correct.
<div>{{'1987-06-15T00:00:00.000Z' | date}}</div>
The string 1987-06-15T00:00:00.000Z
represents different dates in different browser time zones.
Fix
If you don't want to change the date based on time zone, just use string parsing (e.g. substr
) and not date parsing.
This code is worked for me
<div>{{date_of_birth.split("T")[0] | date}}</div>
来源:https://stackoverflow.com/questions/45582333/angular2-date-pipe-automatically-adding-timezone-to-date