0

I have a json format

{
endDate:"2017-05-15Z"
id:"9od718ztlx8dffe3f1q78bc1t"
name:"Clausura - Quarter-finals"
startDate:"2017-05-11Z"
**time:"01:00:00Z"**
}

I need convert the time to gmt. I try with various pipes but the result always is the same. Anyone know if I can turn the time with any pipe? My error is this with any pipe

EXCEPTION: Error in ./CalendarComponent class CalendarComponent - inline template:11:16 caused by: Invalid argument '01:00:00Z' for pipe 'DatePipe'
rene
  • 41,474
  • 78
  • 114
  • 152
Edu Sil
  • 1
  • 1

1 Answers1

0

You should parse your date in a Date object before passing it to date pipe.

As your date seem to be an ISO 8601, but a bit malformed (only date, no hour:min:sec), Date.parse should be able to handle it.

First of all, parse your string using Date:

let dateObj = Date.parse(yourObject.time)

and then, pass this date object to your template using date pipe:

{{dateObj | date}}

Supamiu
  • 8,501
  • 7
  • 42
  • 76
  • Hello I think it's backwards, it only brings hours, minutes and seconds Apparently date.parse if you have a date The result with date.parse gives me NaN =( – Edu Sil May 19 '17 at 18:30