JS如何將UTC格式時間轉本地格式
更新時間:2013年09月04日 17:37:19 作者:
UTC格式時間想必大家并不陌生,那么怎么可以將其轉換為本地格式呢?其實很簡單,下面的方法會幫助大家實現這一想法
復制代碼 代碼如下:
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}
var TempDate = new Date();
TempDate.toLocaleDateString()//2013年9月4日
TempDate.format("yyyy-MM-dd")//2013-09-04
相關文章
For循環(huán)中分號隔開的3部分的執(zhí)行順序探討
這篇文章主要探討了For循環(huán)中分號隔開的3部分的執(zhí)行順序,需要的朋友可以參考下2014-05-05
讓低版本瀏覽器支持input的placeholder屬性(js方法)
低版本瀏覽器一般都不會支持input的placeholder屬性,接下來使用js實現下,感興趣的朋友可以參考下哈2013-04-04

