In IE 8 dates are NaN/Nan/Nan

2019-08-27 19:25发布

问题:

In IE8 my dates are not appearing properly. I have tried many implementations but they are not working properly. Here is what I had originally that works in FF, Chrome and IE9.

var date = TranslateDate(new Date(CreatedDate);

where CreatedDate is a c# datetime object.

function TranslateDate(d) {
    return GetMonth(d) + '/' + GetDay(d) + '/' + d.getFullYear();
}

function GetMonth(d) {
    var month = d.getMonth() + 1;
    return (('' + month).length < 2 ? '0' : '') + month;
}

function GetDay(d) {
    var day = d.getDate();
    return (('' + day).length < 2 ? '0' : '') + day;
}

Any help would be appreciated!

回答1:

By far the easiest solution was to use moment.js. Make sure you save the file instead of looking it up based on a url for IE 8.