JS 时间格式化函数
02 |
Date.prototype.format = function (format) { |
04 |
"M+": this.getMonth() + 1, |
06 |
"h+": this.getHours(), |
07 |
"m+": this.getMinutes(), |
08 |
"s+": this.getSeconds(), |
09 |
"q+": Math.floor((this.getMonth() + 3) / 3), |
10 |
"S": this.getMilliseconds() |
12 |
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); |
13 |
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)); |
使用方法:
1 |
new Date(blog.AddTime).format('yyyy-MM-dd hh-mm-ss'); |
返回 如: 1911-11-11 00-00-00 格式