Angular2 - convert unfortunately date

2019-09-15 18:55发布

问题:

I have a problem - I use c# Web.api and Angular2. Thats works but Angular convert the date which I do not want / need. The date of the database is correct and angular add 1 hour

{{item.createdate | date:'H:mm' }}

So it shows 20:30 instead of 19:30 which is stored in the database :(

This is part of json repsone: "createdate": "2016-11-29T19:30:00",

How can I solve this?

Thank you Ralf

回答1:

The Reason is there's no timezone information in the datetime string from the database result.

var date = new Date('2016-11-29T19:30:00');
console.log(date); //Tue Nov 29 2016 20:30:00 GMT+0100 (CET)

Written in the Angular2 documentation about the Date Pipe here.

The expression expects a valid datestring format:

YYYY-MM-DDThh:mmTZD (eg 2016-11-29T19:30+01:00)

var date = new Date('2016-11-29T19:30+01:00');
console.log(date);  // Tue Nov 29 2016 19:30:00 GMT+0100 (CET)    


标签: date angular