pCloud Partner Program

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

程式技術/Javascript 2017/03/01 16:25
views: 130380 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 omaha seo 2017/11/17 04:29 DELETE

    Subject: omaha seo

    Find the brightest option for b2b advertising agencies currently now in stock and at the best price you can get now!
  2. Tracked from Aroma Sense 2017/11/19 03:41 DELETE

    Subject: Aroma Sense

    See top quality best organic essential oils that's available now and on sale. Get it today!
  3. Tracked from Organic Aroma Sense Oils 2017/11/19 12:36 DELETE

    Subject: Organic Aroma Sense Oils

    See top quality usda certified organic essential oils currently available now and on sale. Get it today!

Write a comment


PREV : [1] : ... [10] : [11] : [12] : [13] : [14] : [15] : [16] : [17] : [18] : ... [472] : NEXT



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


 Waiting...