Date对象是否使用非公历? [英] Does the Date object ever use a non-Gregorian calendar?

查看:109
本文介绍了Date对象是否使用非公历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript中的 Date 对象是否使用非公历?



MDN MSDN 文档概述了 Date 对象和参考 UTC 符合IETF的RFC 2822时间戳



维基百科文章提到


通常使用公历来确定,但也可以使用朱利安日数。


MDN和MSDN文档只是说, UTC方法是指本地时间,但不定义本地时间是什么。



我正在接触一个正在给我的webservice一些数据包括一个日期字段,我需要与当前的日期进行比较。我很清楚依赖于用户机器准确时间的缺陷,并且由于时区不正确和假冒日期设置而导致的任何问题都很好。



但是,关于不使用公历的用户,以及如果我使用 .getDate() .getMonth() .getFullYear()方法计算日期。



所以,实际上,Javascript中的本地时间是指非公历日历系统,如希伯来语或波斯日历?

解决方案

ECMAScript 规范(第3版第5版在这方面几乎相同,但引用第5):


15.9.1.9本地时间



从UTC到本地时间的转换由_
LocalTime(t )= t + LocalTZA + DaylightSavingTA(t)


从本地时间到UTC的转换由 UTC(t)= t - LocalTZA - DaylightSavingTA(t - LocalTZA)


请注意, UTC LocalTime(t))不一定总是等于 t


LocalTZA 是指本地时区调整,而 DaylightSavingTA 是夏令时的调整。 / p>

我没有发现任何浏览器的证据(当前的或历史的)在用户的机器上启用非公历日历时,会有所不同。


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 that UTC(LocalTime(t)) is not necessarily always equal to t.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆