新手求指点,JS中怎么把JSON格式装换成Date类型

元缘圆源 2018-04-26 11:09:52
js中用输出console.log(dd.list[1].createtime)为1378696511000;
...全文
969 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wz334809916 2018-04-27
  • 打赏
  • 举报
回复
function jsonDateFormat(jsonDate) {// json日期格式转换为正常格式 try { var date = new Date(jsonDate); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var hours = date.getHours() < 10 ? "0" + date.getHours() : date .getHours(); ; var minutes = date.getMinutes(); if (minutes < 10) { minutes = "0" + minutes } var seconds = date.getSeconds(); var milliseconds = date.getMilliseconds(); return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes// + "分" + ":" + seconds + "." + milliseconds; } catch (ex) { return "时间错误"; } } 调用方法 console.log(jsonDateFormat(dd.list[1].createtime));
qiheia2 2018-04-26
  • 打赏
  • 举报
回复
console.log(new Date(dd.list[1].createtime).getTime());

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧