這個測試是在Chrome 53
由我添加了一些選項來DateTimeFormat
檢查的日期等字段:
options = {
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
hour12: false, timeZoneName: 'long'
};
var workingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1848 01:00:00 GMT+0100 (BST)'));
var notWorkingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1847 01:00:00 GMT+0100 (BST)'));
其結果是:
workingDate: 10/05/1848, 20:53:32 GMT-03:06:28
notWorkingDate: 10/05/1847, 20:53:32 GMT-03:06:28
大多數地方根本沒有1900(實際上,每個國家在不同的年通過的話)之前,標準化的基於UTC-偏移,所以要在1900年以前,你總會得到那些奇怪的結果實際上,作爲Matt explained in the comments,UTC在1972年實施,在此之前,大多數區域被定義爲與GMT的偏移量。無論如何,對於非常古老的日期,特別是在1900年以前,您可能會預計像上述這樣的偏移量。
在這種情況下,它獲得了我係統的默認時區(America/Sao_Paulo
)的相應偏移量:在1914年之前它是-03:06:28
。
在倫敦(這我假設它的默認時區),before 1847-12-01 the offset was -00:01:15
(由經/緯度計算,詳見再次Matt's comment),之後又改爲+00:00
(這就是爲什麼它工作的日期在1848年)。
我做了一個測試設置時區以Europe/London
:
options = {
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
hour12: false, timeZoneName: 'long', timeZone: 'Europe/London'
};
var workingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1848 01:00:00 GMT+0100 (BST)'));
var notWorkingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1847 01:00:00 GMT+0100 (BST)'));
結果是:
1848年11月5日,00:00:00 GMT
10/05/1847,23:58:45 GMT-00:01:15
這證實在12月/ 1847年之前,日期有不同的偏移量。
人去修補的方式,是考慮日期UTC:
options = {
timeZone: 'UTC'
};
var workingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1848 01:00:00 GMT+0100 (BST)'));
var notWorkingDate = Intl.DateTimeFormat('en-GB', options).format(new Date('Fri May 11 1847 01:00:00 GMT+0100 (BST)'));
值將是:
1848年11月5日
11月5日/ 1847
請參閱[*爲什麼Date.parse會給出錯誤的結果?*](https://stackoverflow.com/questions/2587345/why-do-date-parse-give-incorrect-results) – RobG