Javascript jQuery.datepicker.formatDate 和时区偏移
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7754740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery.datepicker.formatDate and timezone offset
提问by TiTi
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
为了处理日期,我public
在我的应用程序中使用了 jQuery UI方法:jQuery.datepicker.formatDate 在这里查看参数和源: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/
演示在这里:http: //jsfiddle.net/7ACdB/
With a UTC+1 (paris) timezone in windows, i got :
在 Windows 中使用 UTC+1(巴黎)时区,我得到:
03/30/20
03/30/20
With a UTC-6 (us&canada) timezone in windows, i got :
在 Windows 中使用 UTC-6(美国和加拿大)时区,我得到:
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.
当您更改操作系统时区时,您需要重新启动浏览器(至少对于 google chrome 来说是这样)。
My problem is the "03/29/20" date as you can imagine.
我的问题是您可以想象的“03/29/20”日期。
Can somebody explains to me if this is normal or a jquery ui issue ?
有人可以向我解释这是正常现象还是 jquery ui 问题?
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. :-/
我开始认为在美国时区将“2020 年 3 月 30 日星期一 00:00:00 GMT+0200(浪漫夏令时)”显示为 03/29/20 是正常的,但我不太确定。:-/
回答by jk.
What you're getting is correct. Your example sets the time at midnight for Paris. Midnight in Paris is 6PM the day beforein the US for the Eastern Time Zone which I am in.
你得到的是正确的。您的示例将巴黎的时间设置为午夜。巴黎的午夜是我所在的东部时区的前一天下午 6点。
Your first time: GMT+0200 is Paris
您的第一次:GMT+0200 是巴黎
Your second time: GMT-0500 is Chicago (note it is currently Daylight Savings Time)
您的第二次:GMT-0500 是芝加哥(注意现在是夏令时)
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 timein Paris.
因此,当您将时区更改为美国(使用我们的6 个时区之一)时,输出是美国的时间,巴黎的时间是什么时候。
Here is an updated fiddle with a the time set to 6 AM Paris: http://jsfiddle.net/jensbits/7ACdB/1/
这是一个更新的小提琴,时间设置为巴黎早上 6 点:http: //jsfiddle.net/jensbits/7ACdB/1/