Date对象是否使用非公历日历? [英] Does the Date object ever use a non-Gregorian calendar?
问题描述
JavaScript中的 Date
对象是否使用非公历日历?
MDN 和 MSDN docs概述了 Date
对象和引用 UTC 和符合IETF的RFC
维基百科文章提及
MDN和MSDN文档只是说,非常常用的格式记录, UTC方法是指本地时间,但没有定义什么是本地时间。
我正在工作的接口到web服务,一些数据包括年份字段,我需要与当前年份进行比较。我非常清楚依赖于用户机器的准确时间的缺陷,并且对由于时区和伪造日期设置导致的任何问题很好。
我担心的是,关于不使用Gregorian日历的语言环境中的用户,以及如果我使用 .getDate()
, .getMonth()
和 .getFullYear()
因此,在实践中,Javascript中的本地时间是指非公历日历系统,例如希伯来语或波斯日历?
从 ECMAScript 规格(第三版和第5版在这方面几乎完全相同,但引用了第5个):
15.9.1.9当地时间
由UTC到本地时间的转换定义为
$ bLocalTime(t)= t + LocalTZA + DaylightSavingTA(t)
本地时间到UTC的转换定义为
UTC(t)= t - LocalTZA - DaylightSavingTA(t - LocalTZA)
注意UTC(LocalTime(t))
不一定总是等于t
。
LocalTZA
是指本地时区调整, DaylightSavingTA
是对夏令时的调整。
我没有发现任何浏览器(当前或历史)的任何证据,当非公历日历在用户的计算机上启用。
Does the Date
object in Javascript ever use a non-Gregorian calendar?
The MDN and MSDN docs outline the methods on the Date
object and reference UTC and IETF-compliant RFC 2822 timestamps.
The Wikipedia article mentions
Days are conventionally identified using the Gregorian calendar, but Julian day numbers can also be used.
The MDN and MSDN documentation just says that the non-UTC methods refer to the "local time", but doesn't define what "local time" is.
I am working on interfacing to a webservice which is giving me back some data that includes a day-of-year field, which I need to compare to current day-of-year. I am well aware about the pitfalls of relying on an accurate time from a user's machine, and am fine with any problems that result from bad timezones and bogus date settings.
I am concerned, though, about users in locales that don't use the Gregorian calendar, and what their browsers will give back if I use the .getDate()
, .getMonth()
, and .getFullYear()
methods to compute day-of-year.
So, in practice, does "local time" in Javascript ever refer to a non-Gregorian calendar system, such as the Hebrew or Persian calendars?
From the ECMAScript specs (3rd edition and 5th edition are nearly identical in this regard, but am quoting the 5th):
15.9.1.9 Local Time
Conversion from UTC to local time is defined by
LocalTime(t) = t + LocalTZA + DaylightSavingTA(t)
Conversion from local time to UTC is defined by
UTC(t) = t – LocalTZA – DaylightSavingTA(t – LocalTZA)
Note thatUTC(LocalTime(t))
is not necessarily always equal tot
.
LocalTZA
refers to local time zone adjustment, and DaylightSavingTA
is the adjustment for daylight savings.
I have not found any evidence of a browser (current or historic) that does anything different when a non-Gregorian calendar is enabled on a user's machine.
这篇关于Date对象是否使用非公历日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!