在DST轉換期間,我遇到了iOS 8.2 safari的奇怪行爲,同時將datetime字符串轉換爲unix ms時間戳。比方說,我們有js代碼iOS safari getTime()DST行爲
function date2unix(dates){
var len = dates.length;
var result = [], arr;
while(len--) {
arr = dates[len].split(/[- :]/);
result[len]= (new Date(arr[0], arr[1]-1, arr[2], arr[3],arr[4],arr[5]).getTime());
}
return result;
}
var dates =
["2015-03-29 00:00:00","2015-03-29 00:15:00","2015-03-29 00:30:00","2015-03-29 00:45:00","2015-03-29 01:00:00","2015-03-29 01:15:00","2015-03-29 01:30:00","2015-03-29 01:45:00","2015-03-29 03:00:00","2015-03-29 03:15:00","2015-03-29 03:30:00","2015-03-29 03:45:00"];
alert(date2unix(dates))
的iOS 8.2的Safari給出模棱兩可的值(1 == 5日,第二屆== 6日,...),而鍍鉻41.0.2272.101行爲正確。請注意,有爭議的第二小時在數組日期中被忽略。任何人都可以幫我找到解決辦法嗎?
嘗試: http://jsfiddle.net/q6vd0fos/
問候
期望的輸出是1427583600000,1427584500000,1427585400000,1427586300000,1427587200000,1427588100000,14275.89億,1427589900000,1427590800000,1427591700000,1427592600000,1427593500000沒有任何兩面性,iOS裝置給出1427583600000,1427584500000,1427585400000,1427586300000,1427583600000,1427584500000,1427585400000,1427586300000 ,1427590800000,1427591700000,1427592600000,1427593500000 – TauWich 2015-04-03 13:54:03
僅供參考 - 如果不知道計算機配置的時區設置,則無法驗證這些確切結果。 – 2015-04-05 02:45:11