[英]'new Date()' in IE11 does not accept string in ISO 8701 date format with a timezone
以下對Date構造函數的調用可在Chrome,Mozilla和Edge中使用,但不適用於IE11:
new Date("2018-11-01T04:00:00.000+1000");
注意:我從服務器響應中收到日期字符串,因此,我無法控制它
僅在IE11中,我將Invalid Date
作為返回值。 我發現這是由於時區標記( +
向前)的格式所致,因為以下調用可按預期進行:
new Date("2018-11-01T04:00:00.000"); // No timezone
以及這一個:
new Date("2018-11-01T04:00:00.000+10:00"); // Formatted timezone
從IE11中的字符串"2018-11-01T04:00:00.000+1000"
中獲取Date對象有哪些方法?
在適當的位置拼接:
似乎可以完成工作,但是我不確定這是否是最佳解決方案。
謝謝!
正如我所描述的,解決我問題的方法最終是:
在正確的位置進行拼接:
// Call this after making sure the date doesn't contain the : at the appropriate position
function formatExtendedTimezoneIn(originalDate) {
const timezoneDivisorIndex = originalDate.length - 4;
const arr = originalDate.split('');
arr.splice(timezoneDivisorIndex+2, 0, ':');
return arr.join('');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.