问题描述
我正在接收UTC的MySQL时间戳,并试图将其隐藏到客户的本地时区。但是,当我这样做时,会得到错误的时区。
I am receiving a MySQL Timestamp in UTC and trying to covert it to the client's local timezone. However, When i do this I get the wrong time zone.
Ive将我的 DateTime
字符串格式化为: var utcTime = 2014-05-15T13:00:00Z
Ive formatted my DateTime
String to be: var utcTime = 2014-05-15T13:00:00Z
不过,转换后,我的dateObject是: Date {2014年5月15日,星期四,格林尼治标准时间-0400(EDT)}
。但是,我希望我的时区为格林尼治标准时间-0500(EST)。
However when after my conversion my dateObject is: Date {Thu May 15 2014 09:00:00 GMT-0400 (EDT)}
. However, I want my Timezone to be GMT -0500 (EST).
我已经在线搜索了,发现有一种方法可以通过将 UTC附加到
I've searched online and saw there is a way to do this by appending "UTC" to a MYSQL formatted Timestamp.. However, this method does not work in all browsers.
如果有人对转换时区有任何见解,我将不胜感激。
If anyone has any insight on converting timezones i would appreciate it.
推荐答案
EDT中的D表示日光,而EST中的S表示标准。 EDT应该在美国的夏季使用,而EST在冬季使用()。 GMT -4(EDT)实际上是正确的当地时间吗?如果更倾向于冬季,它将自动切换到GMT -5(EST)。客户端时区和夏令时由Javascript自动处理。
The D in EDT stands for Daylight and the S in EST stands for Standard. EDT should be used during Summer in the U.S. and EST in the Winter (list of countries here). Is it possible that GMT -4 (EDT) is actually the right local time? If it would be more towards winter it would switch automatically to GMT -5 (EST). The client timezone together with daylight savings is handled automatically by Javascript.
例如,JavaScript中某个日期的默认字符串表示形式应在标准时间和夏令时之间正确选择。基于日期对象本身和机器时区的时间:
For example, the default string representation of a certain date in Javascript should correctly choose between Standard time and Daylight Savings time based on the date object itself and the machine timezone:
var date = new Date(millisSinceUnixEpoch);
alert(date.toDateString() + ' ' + date.toTimeString());
注意:尽管如此,仍有很多假设的余地。例如。不确定您的向本地时区转换代码的样子
Note: there's room for a lot of assumption though. E.g. not sure exactly how your 'conversion to local timezone' code looks like
这篇关于Javascript日期给我EDT但我想要EST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!