2

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?

R. Oosterholt
  • 7,720
  • 2
  • 53
  • 77
lakhan
  • 255
  • 7
  • 14

4 Answers4

1

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

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

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

Muhammed Albarmavi
  • 23,240
  • 8
  • 66
  • 91
0

Date in my TS file -

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

in the html

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

Vedant Karpe
  • 71
  • 1
  • 5
0

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)

DrFreeze
  • 137
  • 10