zoukankan      html  css  js  c++  java
  • JS中j将JSON格式装换成Date类型

    js中用输出console.log(dd.list[1].createtime)为1378696511000

    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));
    谢谢大家的阅读,阅读后记得关注一下呦!
  • 相关阅读:
    axios express设置跨域允许传递cookie
    yarn常用命令指北
    Web代理工具NProxy
    DevOps的了解
    css图片hover放大
    autoprefixer
    谈谈浏览器http缓存
    欢迎使用 MWeb
    优化关键渲染路径CRP
    chrome 61 更新
  • 原文地址:https://www.cnblogs.com/bhy-1116/p/9560013.html
Copyright © 2011-2022 走看看