javascript - 转换 2014-11-03T00 :00:00 to yyyy-mm-dd in javascript

标签 javascript datetime internet-explorer-8

我尝试使用 yyyy-mm-dd 更改此日期

function convert(str) {                
                var date = new Date(str);
                var mnth = ("0" + (date.getMonth() + 1)).slice(-2)
                var day = ("0" + date.getDate()).slice(-2);
                return [date.getFullYear(), mnth, day].join("-");
            }   

但它在 i.e 8 中给了我 Naan 错误。它适用于所有其他浏览器。

有人可以帮我吗?

谢谢

最佳答案

你想从

2014-11-03T00:00:00 

yyyy-mm-dd 

你只需要

function convert(str) {
  return str.split("T")[0];
}

要从带有 T 和破折号的日期创建日期,请尝试

function convert(str) {
  var parts = str.split("T");
  var dParts = parts[0].split("-");
  var tParts = parts[1].split(":");
  return new Date(dParts[0],dParts[1],dParts[2],tParts[0],tParts[1],tParts[2]);
}
var d = convert("2014-11-03T00:00:00");
alert(d);

关于javascript - 转换 2014-11-03T00 :00:00 to yyyy-mm-dd in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26801192/

相关文章:

html - IE8 - 在链接的 div 中单击图像时,链接不起作用

jquery - 使用 jQuery 读取 CSV 文件

javascript - 从全日历中删除时间

javascript - localhost 不工作的简单 angularJS GET 函数

javascript - 粘性导航和 coverflow 插件出错

python - 按日期和时间查询存储在 MongoDB 中的数据

javascript - 首个网站,需要某些点击功能的帮助

python - 如何获取 datetime64[ns] 的时间偏移信息

两个日期戳之间的MySQL时间选择

JavaScript:input type=checkbox 是否可以在 IE8 中使用 appendChild?