JS时间戳转日期格式
2016-07-01 Js 1577
Date.prototype.format = function(format) {
var date = {
\"M+\": this.getMonth() + 1,
\"d+\": this.getDate(),
\"h+\": this.getHours(),
\"m+\": t
Date.prototype.format = function(format) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S+": this.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}
var newDate = new Date();
newDate.setTime(1467361131*1000);
console.log(newDate.format('yyyy-MM-dd h:m:s'))
//2016-07-01 16:18:51
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论