如何避免 JQuery datepicker 的时区问题 [英] How to avoid time zone issues with JQuery datepicker

查看:11
本文介绍了如何避免 JQuery datepicker 的时区问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在输入表单中使用 datepicker,并通过 json 将结果发送到数据库.我正在使用这一行,从 datePicker 获取日期:

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'); 

现在,我希望它返回 2014-04-03T00:00:00.000Z

但实际上它返回2014-04-02T22:00:00.000Z

请注意两个小时的差异,这也会无意中改变月份中的某一天.我没有使用小时和较小的时间单位.但是我确实希望日期是正确的,而不是在我的代码中添加可怕的 +1.我怀疑这与时区有关,但我似乎无法在文档或其他在线问答中找到解决方案.有人能指出我正确的方向吗?如果重要的话,我的时区是 GMT +1.

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.

谢谢:)

推荐答案

我不久前解决了这个问题,但忘记发布答案.检索date后,这是我修复它的方式:

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());

这篇关于如何避免 JQuery datepicker 的时区问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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