js时间格式
2016-03-10 16:14
274 查看
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 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;
}
相关文章推荐
- com.alibaba.fastjson.JSONException: unclosed string
- gson JsonParser
- json 转义字符
- js不停地触发按钮的事件
- JSON There is a cycle in the hierarchy异常
- JS正则表达式获取分组内容实例
- selenium 执行 js
- javascript实例学习之五——瀑布流布局
- JSONP跨域的原理解析
- Velocity浅析及与Jsp、Freemarker对比
- Thickbox。js
- js 小技巧总结
- js 分页 对象
- js创建对象的几种常用方式
- js json 增删改查
- js json 增删改查
- selenium phantomjs
- jsp 获取当前请求的值
- ajax 加载 页面 执行 js
- js中document.write的那点事