如何避免JQuery datepicker的时区问题 [英] How to avoid time zone issues with JQuery datepicker
问题描述
我在输入表单中使用datepicker,并通过json将结果发送到数据库。我正在使用这一行,从datePicker获取日期:
date = $(#datepicker)。datepicker 'getDate');
现在,我希望这可以返回 2014-04-03T00:00 :00.000Z
但实际上它返回 2014-04-02T22:00:00.000Z
注意两小时差异,这也意味着每月的变化。我没有用的时间和较小的时间单位。不过,我希望日期是正确的,而不会在我的代码中添加可怕的 +1
。我怀疑这与时区有关,但我似乎无法在文档或其他Q& A的在线中找到解决方案。有人可以指出我的方向正确吗?我的时区是GMT +1,如果这很重要。
谢谢:)
我刚才解决了这个问题,但忘了发一个答案。
检索日期
后,这是我如何修复:
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
voilla
I'm using datepicker in an input form, and sending the results through json to a database. I am using this line, to get the date from the datePicker:
date = $("#datepicker").datepicker('getDate');
Now, I would expect this to return 2014-04-03T00:00:00.000Z
But in fact it returns 2014-04-02T22:00:00.000Z
Notice the two hour difference, which unintentionally changes the day of month as well. I have no use for the hours and the smaller time units. However I do want the date to be right, without adding a dreaded +1
to my code. I suspect this has something to do with time zones, but I can't seem to find a solution to it in the documentation, or other Q&A's online. Could anyone point me in the right direction? My time zone is GMT +1 if that matters.
Thanks :)
I solved this a while ago, but forgot to post an answer.
After retrieving date
, this is how i fixed it:
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
voilla
这篇关于如何避免JQuery datepicker的时区问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!