JS时间戳转换成时间格式

TimeNow: function (val) {
        var date = new Date(val);

        var Y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        var H = date.getHours();
        var i = date.getMinutes();
        var s = date.getSeconds();
        if (m < 10) m = '0' + m;
        if (d < 10) d = '0' + d;
        if (H < 10) H = '0' + H;
        if (i < 10) i = '0' + i;
        if (s < 10) s = '0' + s;

        var t = Y + '-' + m + '-' + d + ' ' + H + ':' + i + ':' + s;
        return t;
}

 

posted @ 2018-04-03 15:22  _Iniesta  阅读(193)  评论(0编辑  收藏  举报