Javascript Invalid Date Error in Internet Explorer

后端 未结 5 1785
野趣味
野趣味 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条回答
  •  -上瘾入骨i
    2020-11-28 12:12

    I was having the same issue with Internet Explorer. This is how I was formatting the date and time initially,

    function formatDateTime(date, formatString = 'MM/DD/YYYY hh:mm A') {
      return moment(new Date(date)).format(formatString);
    }
    

    The problem was with new Date(). I just removed it as it was already a UTC date. So it is just,

    return moment(date).format(formatString);
    

    This worked for me in all browsers including IE.

提交回复
热议问题