Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 date pipe automatically adding timezone to date

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>
like image 536
byteC0de Avatar asked Aug 09 '17 05:08

byteC0de


People also ask

What is DatePipe in angular?

DatePipe is used to format a date value according to locale rules. Syntax: {{ value | date }} Approach: Create the angular app that to be used. There is no need for any import for the DatePipe to be used.


1 Answers

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.

like image 198
basarat Avatar answered Oct 20 '22 11:10

basarat