5

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>
byteC0de
  • 5,153
  • 5
  • 33
  • 66

2 Answers2

4

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.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Is there is any option in date pipe? – byteC0de Aug 09 '17 at 05:37
  • Nope. It is meant to represent a given date in the user's time zone. – basarat Aug 09 '17 at 05:38
  • 1
    From the Source code: WARNINGS: - this pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera browsers. https://github.com/angular/angular/blob/4.3.3/packages/common/src/pipes/date_pipe.ts#L16-L143 – Max Aug 09 '17 at 05:38
4

This code is worked for me

<div>{{date_of_birth.split("T")[0] | date}}</div>
byteC0de
  • 5,153
  • 5
  • 33
  • 66