zoukankan      html  css  js  c++  java
  • JavaScript--日期格式化

    平时用前端框架做项目,从数据库中读取的时间,老是是时间戳或者其它的一些格式,总结一下两个常用的格式化日期的方式!

    //js将"2018-05-19T08:04:52.000+0000"这种格式的时间转化为正常格式
    function DateTimeFormatter(value) {
        if (value != null) {
            var dateee = new Date(value).toJSON();
            var date = new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/.[d]{3}Z/, '');
            return date;
        }
        else {
            return null;
        }
    }
    //将时间戳转换为正常格日期
    function DateTimeFormatters(value) {
        if (value == undefined) {
            return "";
        }
        /*json格式时间转js时间格式*/
        value = value.substr(1, value.length - 2);
        var obj = eval('(' + "{Date: new " + value + "}" + ')');
        var dateValue = obj["Date"];
        if (dateValue.getFullYear() < 1900) {
            return "";
        }
        var date = new Date(dateValue);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + '/' + m + '/' + d;
        return date;
    }
  • 相关阅读:
    盒子模型中问题
    outline
    高度自动相等方法
    正则表达式
    绝对定位 相对定位
    replace 使用函数作为第二参数
    float 浮动
    line-height 行高
    元素隐藏
    现代浏览器内部
  • 原文地址:https://www.cnblogs.com/dcy521/p/10981302.html
Copyright © 2011-2022 走看看