pCloud Partner Program

javascript跨瀏覽器解析日期時間字串問題

程式技術/Javascript 2017/03/01 09:25
views: 78090 times
在前端使用 javascript 解析日期時間字串時, 在不同瀏覽器有不同的解讀, 我們來看一下:

2017-03-01T16:00:00

這個字串若是以 Firefox 與 IE 來解讀, 是 localtime, 若是以 Chrome 來解讀則是 GMT, 測試網址如下: https://jsfiddle.net/timhuang/8paLsfyr/2/

若是希望都是以 GMT 來解讀, 可以多加一個 Z 在字串的最後, 如: 2017-03-01T16:00:00Z 就會讓各瀏覽器取得一樣的 GMT 結果, 測試網址一下在上面.

所以若是在前端, 使用 javascript 處理日期時間字串時, 一定要理解與清楚這個狀況, 否則可能會有跨瀏覽器不一致的狀況.

參考資料: http://stackoverflow.com/questions/15109894/new-date-works-differently-in-chrome-and-firefox


top

Trackback Address :: http://diary.tw/tim/trackback/1172

  1. Tracked from metal building contractors 2017/05/23 04:57 DELETE

    Subject: metal building contractors

    Find here the best commercial building contractor currently available plus at the best price today!
  2. Tracked from quartz clock movements and hands 2017/05/27 07:39 DELETE

    Subject: quartz clock movements and hands

    Find here the top option for clock parts currently available and at great prices you can get now!
  3. Tracked from anchor 2017/05/27 18:43 DELETE

    Subject: anchor

    See professional tenant improvements construction that are now in stock and at great prices today!

Write a comment


PREV : [1] : [2] : [3] : [4] : [5] : [6] : [7] : [8] : ... [462] : NEXT



Nextbit Robin 5.2吋六核心智慧型手機 Microsoft Office 365 中文家用版PKC (無光碟)
ASUS華碩 AC1900 雙頻無線路由器 RT-AC68U 美國 VORNADO 533 渦流空氣循環機 (黑色)
御茶園 每朝健康綠茶(650mlx24入) 每朝健康 雙纖綠茶(650mlx24入)


 Waiting...