jQuery.datepicker.formatDate and timezone offset

梦想的初衷 提交于 2019-12-01 20:29:26

问题


To handle dates, i'm using a jQuery UI public method in my application: jQuery.datepicker.formatDate See params & source here : https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js

However the wrong date is displayed sometimes, according to the computer timezone.

Demo here : http://jsfiddle.net/7ACdB/

With a UTC+1 (paris) timezone in windows, i got :

03/30/20
03/30/20

With a UTC-6 (us&canada) timezone in windows, i got :

03/29/20 <- meh!
03/30/20

You need to restart your browser (well for google chrome at least) when you change the OS timezone.

My problem is the "03/29/20" date as you can imagine.

Can somebody explains to me if this is normal or a jquery ui issue ?

I'm beginning to think that it is normal to see a "Mon Mar 30 2020 00:00:00 GMT+0200 (Romance Daylight Time)" as 03/29/20 in a US timezone but i'm not so sure. :-/


回答1:


What you're getting is correct. Your example sets the time at midnight for Paris. Midnight in Paris is 6PM the day before in the US for the Eastern Time Zone which I am in.

Your first time: GMT+0200 is Paris

Your second time: GMT-0500 is Chicago (note it is currently Daylight Savings Time)

So, when you change the time zone to US (using one of our 6 time zones), the output is the time in the US when is that time in Paris.

Here is an updated fiddle with a the time set to 6 AM Paris: http://jsfiddle.net/jensbits/7ACdB/1/



来源:https://stackoverflow.com/questions/7754740/jquery-datepicker-formatdate-and-timezone-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!