我得到了一段从xml文件中获取日期的代码片段。我发现了一个代码转换日期dd/mm/yyyy。此代码在Google Chrome中正常工作,但在Firefox,IE或Edge中无法正常工作... 在浏览器中代码无法正常工作,函数将返回NaN/NaN/NaN。但例如:在谷歌浏览器中,重新启动了12/2/2016。 dateFormXml的格式为yyyy/MM/DD和输出格式为DD/MM/YYYY 这里是我的代码:函数getDate在FireFox和IE中不起作用
function dateConverter(dateFromXml){
function format(x){
//if the day/month is smaller then 10 add a 0 in front of it (9->09)
return (s < 10) ? '0' + x : x;
}
var d = new Date(dateFormXml),
convertedDate = [format(d.getDate()), format(d.getMonth() + 1), d.getFullYear()].join('/');
return convertedDate;
}
谁能帮我做这个跨浏览器吗? :)
你能解释你的代码吗?看起来像缺少一些东西 - 'dateFromXml'没有被使用,'date'没有被定义 –
,同时也发布了样本'dateFromXml'格式被传递给函数 – Nirus
[Date构造函数可能在IE中返回NaN,但在Firefox和Chrome](http://stackoverflow.com/questions/2182246/date-constructor-returns-nan-in-ie-but-works-in-firefox-and-chrome) –