角度材料的日期选择器错误的日期 [英] Wrong date with angular material's date picker

查看:84
本文介绍了角度材料的日期选择器错误的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用datepicker选择日期并将其发送到服务器。

I use the datepicker to pick a date and send it to the server.

当我记录JS值时,我得到了正确的结果:

When I log the JS value I get the correct result:

Tue Mar 22 2016 00:00:00 GMT+0100 (Mitteleuropäische Zeit)

但是在ajax请求中它是

but in the ajax request it is

2016-03-21T23:00:00.000Z

我不修改值,只是给对象提供angulars http功能。

I don't modify the values, just giving the object to angulars http function.

Angular是否需要一些配置来处理它?<​​/ p>

Does Angular need some configuration to handle it?

推荐答案

这两个字符串代表同一时间。一个是UTC,即GMT +0,您可以从 Z 结尾看到。另一个是在不同的时区,特别是GMT +1小时。

Those two strings represent the same time. One is in UTC, i.e. GMT +0, which you can see from the Z ending. The other is in a different timezone, specifically GMT +1 hour.

如果你有两个字符串的javascript日期对象,并将它们变成整数,即自1月以来经过的秒数1,1970,UTC,你会发现它们是相同的。它们代表相同的即时,但位于两个不同的地理位置

If you had javascript date objects for both strings, and turned them into integers, i.e. seconds passed since Jan 1, 1970, UTC, you'd find them identical. They represent the same instant but in two different geographic locations.

var d1 = new Date('Tue Mar 22 2016 00:00:00 GMT+0100');
var d2 = new Date('2016-03-21T23:00:00.000Z');

Number(d1);  // 1458601200000
Number(d2);  // 1458601200000

一般来说,这是一件好事。处理时区变得非常混乱。我觉得服务器最好总是用UTC进行交易。

Generally this is a good thing. Dealing in timezones gets very confusing. I find it best for a server to always deal in UTC.

这篇关于角度材料的日期选择器错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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