EEST时区的Javascript日期函数错误(Javascript Date function bug on EEST timezones)

编程入门 行业动态 更新时间:2024-10-19 10:20:57
EEST时区的Javascript日期函数错误(Javascript Date function bug on EEST timezones) new Date("May 27, 2011, 1:00 pm EEST")

萤火虫响应:

Date {Invalid Date}

这是一个已知的javascript错误吗? 你如何用日期解释javascript中的“东欧夏令时”时区?

我可以将时区更改为+03:00或+0300,但是对于用户来说它不会那么友好,因为我使用<abbr>标签和jQuery我将每个abbr innerHTML格式化为他们的标题值是的,所以当你将鼠标悬停在它上面时,我仍然希望工具提示显示“2011年5月27日,美国东部时间下午1点”,但在innerHTML中我只需要“2011年5月27日”

<abbr class="timestamp blue" title="May 27, 2011, 1:00 pm EEST">May 27, 2011</abbr>

但是,因为EEST,我得到了这个

<abbr class="timestamp blue" title="May 27, 2011, 1:00 pm EEST">NaN</abbr>

如果我将EEST更改为更常见的东西,例如EST或GMT,那么没问题,很奇怪。

new Date("May 27, 2011, 1:00 pm EEST")

Firebug Response:

Date {Invalid Date}

Is this a known javascript bug ? how do you interpret the "Eastern European Summer Time" timezone in javascript with date ?

I can change the timezone to +03:00 or +0300 for example, but then it wouldn't be as friendly for the user, because im using the < abbr > tag and with jQuery i format each abbr innerHTML to what their title value is, so that when you hover over it, I still want the tooltip to display "May 27, 2011, 1:00 pm EEST", but in innerHTML i only need "May 27, 2011"

<abbr class="timestamp blue" title="May 27, 2011, 1:00 pm EEST">May 27, 2011</abbr>

However, because of EEST, i get this

<abbr class="timestamp blue" title="May 27, 2011, 1:00 pm EEST">NaN</abbr>

If i change EEST to something more common such as EST or GMT, then no problem, weird.

最满意答案

从ECMA脚本规范 (15。15。15日期时间字符串格式):

没有国际标准规定民用时区的缩写,如CET,EST等,有时相同的缩写甚至用于两个非常不同的时区。 因此,ISO 8601和此格式指定了日期和时间的数字表示。

来自ISO 8601

ISO 8601中没有时区指示符。时间仅表示为本地时间或与UTC相关

简而言之:它不是一个bug。 您不能在javascript Date对象中使用EEST之类的区域。 你必须坚持'UTC'或+/-表示法。

您可以在@this网页上找到有关该主题的大量信息

From the ECMA-script specification (15.9.1.15 Date Time String Format):

There exists no international standard that specifies abbreviations for civil time zones like CET, EST, etc. and sometimes the same abbreviation is even used for two very different time zones. For this reason, ISO 8601 and this format specifies numeric representations of date and time.

From ISO 8601

There are no time zone designators in ISO 8601. Time is only represented as local time or in relation to UTC

In short: it's not a bug. You can't use zones like EEST and the like in the javascript Date object. You'll have to stick to 'UTC' or the +/- notation.

You can find a lot of information on the subject @this webpage

更多推荐

本文发布于:2023-07-23 18:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235637.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   时区   错误   日期   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!