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>
2
  • You want output like dd/MM/yyyy ? Commented Aug 9, 2017 at 5:35
  • You can specify format in date pipe. If you are not happy with available date pipe formats, you can create and register your own pipe in the module. Commented Aug 9, 2017 at 5:36

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there is any option in date pipe?
Nope. It is meant to represent a given date in the user's time zone.
From the Source code: WARNINGS: - this pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera browsers. github.com/angular/angular/blob/4.3.3/packages/common/src/pipes/…
4

This code is worked for me

<div>{{date_of_birth.split("T")[0] | date}}</div>

1 Comment

Cleaner/slower/better/worse? <div>{{date_of_birth | splice: 0:10 | date}}</div>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.