JavaScript-long 转为时间格式

2018-05-24  本文已影响0人  TheUnforgiven
格式为: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);
};
上一篇 下一篇

猜你喜欢

热点阅读