Problem with date formats in JavaScript with different browsers

前端 未结 4 774
抹茶落季
抹茶落季 2020-11-27 20:21

I am working with dates in an RSS feed, but am finding differing results when using the code below in IE, Chrome and Firefox:

new Date(\'2001-01-01T12:00:00Z         


        
相关标签:
4条回答
  • 2020-11-27 21:05

    You could also try using Date.js - an open source javascript date manipulation library.

    0 讨论(0)
  • 2020-11-27 21:07

    This works on all of the major 5 browsers and causes all browsers to recognize the time as GMT/UTC rather than local time (the Z suffix means the time is UTC):

    new Date('2001-01-01T12:00:00Z'.replace(/\-/g,'\/').replace(/T/,' ').replace(/Z/,' -0'))
    

    I thank mplungjan for his answer.

    0 讨论(0)
  • 2020-11-27 21:09

    This works in all browsers on my box - try it in the console:

    alert(new Date('2001/01/31 12:00:00'))
    

    so

    new Date('2001-01-01T12:00:00Z'.replace(/\-/g,'\/').replace(/[T|Z]/g,' '))
    

    IE8, FF3.6, Safari4, Chrome

    0 讨论(0)
  • 2020-11-27 21:20

    Can you try:

    new Date(2001,0,1,12,0,0)
    

    This means:

    new Date(year,month,day,hour,minutes,seconds) 
    
    0 讨论(0)
提交回复
热议问题