pCloud Partner Program

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

程式技術/Javascript 2017/03/01 16:25
views: 117540 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 clock kit manufacturer 2017/07/20 02:40 DELETE

    Subject: clock kit manufacturer

    See the best available clocks dials faces that are now in stock in addition at great prices you can get now!
  2. Tracked from Tree Slice Coffee Table 2017/07/20 17:45 DELETE

    Subject: Tree Slice Coffee Table

    Find the best option for Dumonds dining room set that's available in addition currently on sale you can get now!
  3. Tracked from school pa system 2017/07/20 21:31 DELETE

    Subject: school pa system

    Get top quality wireless pa system currently in stock and at the best price. Get it now!
  4. Tracked from browse this site 2017/07/21 13:37 DELETE

    Subject: browse this site

    Find here the best available clock dials that's in stock in addition at the best price you can get now!
  5. Tracked from Dumonds Furniture 2017/07/21 23:29 DELETE

    Subject: Dumonds Furniture

    Get the top new Wooden log side table now now in stock and reasonably priced you can get now!
  6. Tracked from Custom Computer Desk 2017/07/22 03:34 DELETE

    Subject: Custom Computer Desk

    Find here the brightest option for Dumonds currently in stock plus reasonably priced you can get now!
  7. Tracked from browse this site 2017/07/22 16:19 DELETE

    Subject: browse this site

    Find here the brightest option for Barn Wood Dining Room Table currently available plus on sale you can get now!
  8. Tracked from metal building construction 2017/07/23 18:02 DELETE

    Subject: metal building construction

    Get top quality tenant improvement contractor currently in stock plus currently available today!
  9. Tracked from large building contractors 2017/07/24 20:04 DELETE

    Subject: large building contractors

    Get top quality Tenant Improvement that's in stock and reasonably priced today!
  10. Tracked from wholesale clock movements 2017/07/26 21:23 DELETE

    Subject: wholesale clock movements

    See the greatest new clock kits currently available plus reasonably priced you can get now!

Write a comment


PREV : [1] : ... [3] : [4] : [5] : [6] : [7] : [8] : [9] : [10] : [11] : ... [465] : NEXT



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


 Waiting...