In IE 8 dates are NaN/Nan/Nan

倾然丶 夕夏残阳落幕 提交于 2019-12-24 22:06:56

问题


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.



来源:https://stackoverflow.com/questions/15319479/in-ie-8-dates-are-nan-nan-nan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!