美文网首页
JavaScript-long 转为时间格式

JavaScript-long 转为时间格式

作者: TheUnforgiven | 来源:发表于2018-05-24 15:30 被阅读0次
格式为:2018/05/20/ 10:29:20
function timeFormatter(value) {
    var unixTimestamp = new Date(value);
    return unixTimestamp.toLocaleString();
}
function prefixInteger(num, length) {
    return (Array(length).join('0') + num).slice(-length);
}
Date.prototype.toLocaleString = function() {
    return this.getFullYear() + "/" + prefixInteger((this.getMonth() + 1), 2)
            + "/" + prefixInteger(this.getDate(), 2) + "/ "
            + prefixInteger(this.getHours(), 2) + ":"
            + prefixInteger(this.getMinutes(), 2) + ":"
            + prefixInteger(this.getSeconds(), 2);
};

相关文章

网友评论

      本文标题:JavaScript-long 转为时间格式

      本文链接:https://www.haomeiwen.com/subject/dcssjftx.html