![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
function getDayFormat(sDay,iAdd)
{
var cday=new Date(Date.parse(sDay.replace(/-/g, "/")));
cday.setDate(cday.getDate()+iAdd);
return cday.format("yyyy-MM-dd");
} ![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Date.prototype.format = function(format)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(var k in o)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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;
}
posted @
2009-09-04 14:06
-阿飞-
阅读(
162)
评论()
编辑
收藏
举报