//时间格式设置 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+ :
//时间格式设置
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 d = new date();
d.format(h);
//判断时间
function convertdate(strdate) {
strdate = strdate.replace(/-/ig,'/');
var d = new date(strdate);
var now = new date();
var result;
if (d.getyear() == now.getyear() && d.getmonth() == now.getmonth()) {
var xday = now.getdate() - d.getdate();
switch (xday) {
case 0:
result = 今天 + d.format(hh) + : + d.format(mm) + : + d.format(ss);
break;
case 1:
result = 昨天 + d.format(hh) + : + d.format(mm) + : + d.format(ss);
break;
case 2:
result = 前天 + d.format(hh) + : + d.format(mm) + : + d.format(ss);
break;
default:
result = d.format(yyyy-mm-dd hh:mm);
break;
}
} else {
result = d.format(yyyy-mm-dd hh:mm);
}
return result;
}