Angular2-不幸的是转换日期 [英] Angular2 - convert unfortunately date

查看:66
本文介绍了Angular2-不幸的是转换日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题-我使用c#Web.api和Angular2。没问题,但是Angular转换了我不需要/需要的日期。数据库的日期是正确的,并且按角度添加了1小时

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'}}

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

因此它显示的是20:30,而不是存储在数据库中的19:30:(

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

这是json repsone的一部分:
createdate: 2016-11-29T19:30:00,

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

我该如何解决?

谢谢
Ralf

Thank you Ralf

推荐答案

原因是数据库结果中的datetime字符串中没有时区信息。

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)

写在有关日期管道的Angular2文档中此处

Written in the Angular2 documentation about the Date Pipe here.

表达式需要有效的日期字符串格式:

The expression expects a valid datestring format:

YYYY-MM-DDThh:mmTZD(例如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)    

这篇关于Angular2-不幸的是转换日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆