js格式化时间
2016-05-23 00:00
465 查看
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 dateTime = new Date().format('hmsS');
{
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 dateTime = new Date().format('hmsS');
相关文章推荐
- javascript中的事件
- js图片放大缩小
- 发起JSONP请求
- js格式化日期
- js 判断 用户浏览器所在平台
- JS如何实现抛物线动画
- threejs(二) 移动,相机
- 谈一谈Javascript内存释放那点事
- js中的prototype_记录
- 关于JSP中PreparedStatement的使用
- 如何将JS里变量的值赋给文本框
- 智能社JavaScript基础--1~7节课程.docx
- JavaScript eval()表达式
- 推荐8个实现 SVG 动画的 JavaScript 库
- Javascript Event loop 详解(youtube视频,个人备忘)
- JS入门--插入JS代码
- JSTL标签
- JS Map 和 List 的简单实现
- javascript闭包理解
- JavaScript阻塞剖析与改善