手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS如何将UTC格式时间转本地格式
JS如何将UTC格式时间转本地格式
摘要:复制代码代码如下:Date.prototype.format=function(format){varo={"M+":this.getMon...

复制代码 代码如下:

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

【JS如何将UTC格式时间转本地格式】相关文章:

html下载本地

如何制作浮动广告

js获取字符串字节数方法小结

javaScript中with函数用法实例分析

生成html静态文件后的分页(客户端版)

如何控制框架页的滚动

JavaScript实现点击文字切换登录窗口的方法

Javascript类型转换的规则实例解析

javascript实现删除前弹出确认框

Bootstrap基础学习

精品推荐
分类导航