Angular2 date pipe automatically adding timezone to date

a 夏天 提交于 2019-12-07 06:30:23

问题


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>

回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!