复制代码 代码如下:
function dateformat(date, format) {
var o = {
m+: date.getmonth() + 1, //month
d+: date.getdate(), //day
h+: date.gethours(), //hour
m+: date.getminutes(), //minute
s+: date.getseconds(), //second
q+: math.floor((date.getmonth() + 3) / 3), //quarter
s: date.getmilliseconds() //millisecond
};
//把yyyy替换成具体的年份
if (/(y+)/.test(format)) {
format = format.replace(regexp.$1, (date.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 ? ((000 + o[k]).substr(( + o[k]).length)) : (00 + o[k]).substr(( + o[k]).length));
}
}
return format;
}