lakhan
lakhan

Reputation: 265

How do I convert '2019-02-22T12:11:00Z' to 'DD/MM/YYYY HH:MM:SS' format in angular

I am working on some API clockify API integration. I am getting all time entries from the API. in the response I am getting start & end time of the task in the 2019-02-22T12:11:00Z.

I want to convert above date format in DD/MM/YYYY HH:MM:SS format. I have used date pipe for this {{item.timeInterval.start | date: dd/MM/yyyy, h:mm a z}} but its not working. it displays the same.

How can I achieve this?

Upvotes: 2

Views: 593

Answers (4)

Muhammed Albarmavi
Muhammed Albarmavi

Reputation: 24472

Your date format is wrong 🤔 any wrong format will not parse as an example YYYY format will return YYYY but yyyy will return the year 2019 check the documentation for the all format option her

{{'2019-02-22T12:11:00Z' | date : "dd/MM/yyy HH:mm:ss"}}
<br>
{{'2019-02-22T12:11:00Z' | date : "short"}}
<br>
{{'2019-02-22T12:11:00Z' | date : "full"}}
<br>
{{'2019-02-22T12:11:00Z' | date : "yyy"}}

stackblitz demo

Upvotes: 0

DrFreeze
DrFreeze

Reputation: 137

You can just convert your string into a Date object when you receive the data from the API. Just use item.timeInterval.start = new Date(item.timeInterval.start)

Upvotes: 0

Vedant Karpe
Vedant Karpe

Reputation: 81

Date in my TS file -

myDate = '2019-02-22T12:11:00Z';

in the html

{{myDate | date: 'dd/MM/yyyy HH:MM:SS'}}

Upvotes: 0

Pardeep Jain
Pardeep Jain

Reputation: 86800

Try using parse into Date object like this -

parseIntoDate(date){
    return Date.parse(date)
}

<p>{{parseIntoDate(item.timeInterval.start) | date: 'dd/MM/yyyy, h:mm a z'}}</p>

Working Example

Upvotes: 1

Related Questions