JavaScript-long 转为时间格式
格式为: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
网友评论