JS时间格式化
来源:互联网 发布:tower与其他软件 编辑:程序博客网 时间:2024/06/07 20:36
/*
* 时间格式化
*/
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 (date.hasOwnProperty(k)) {
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;
}
* 时间格式化
*/
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 (date.hasOwnProperty(k)) {
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;
}
0 0
- 【js】js时间格式化
- js中格式化时间
- js时间日期格式化
- js 格式化时间
- js 格式化时间函数
- js格式化时间
- js 格式化时间
- js时间格式化
- js中格式化时间
- js 格式化时间
- js的时间格式化
- js 时间格式化
- js格式化时间
- js时间格式化
- js字符串格式化时间
- js 时间格式化
- 用js格式化时间
- js 时间格式化
- JDK自带工具一览表
- OC中的一些编程写法--({"添加代码"})
- DOM1
- css3学习
- 2016.11.13【初中部 NOIP普及组 】模拟赛
- JS时间格式化
- python 连接mysql 并传入数据
- PE 71 72 73 Farey Neighbours (sequence) (farey序列)
- iOS用被误解的MVC重构代码
- [绍棠] masonry在iOS7中报错问题
- Python中错误和异常处理
- 论战大原题
- Mysql 插入中文乱码
- 项目从Tomcat7迁移到Tomcat8后,中文乱码