In IE 8 dates are NaN/Nan/Nan

2019-08-27 19:01发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-27 19:45

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.

查看更多
登录 后发表回答