Javascript Invalid Date Error in Internet Explorer

后端 未结 5 1800
野趣味
野趣味 2020-11-28 11:27

Relatively simple javascript here, not sure why IE hates me (treat others how you want to be treated I suppose).

var newDate = new Date(\"2012, 11, 2 19:30:0         


        
5条回答
  •  盖世英雄少女心
    2020-11-28 12:06

    The string given to the date constructor should be an RFC2822 or ISO 8601 formatted date. In your example it isn't. Try the following:

    new Date("2012-11-02T19:30:00.000Z");
    

    or using an alternate constructor:

    new Date(2012, 11, 2, 19, 30, 0)
    

提交回复
热议问题