发表评论 阅读评论 最近写日期操作的几个JS函数
2010年4月23日
//格式化函数 Date原型扩展
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;
}
// 日期比较
function datecompare(startDate, endDate) {
var re = /^(\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
var d1 = new Date(startDate.replace(/-/g, "/"));
var d2 = new Date(endDate.replace(/-/g, "/"));
if (Date.parse(d1) - Date.parse(d2) == 0) {
// window.alert("两个日期相等");
return "1";
}
if (Date.parse(d1) - Date.parse(d2) < 0) {
// window.alert("结束日期 大于 开始日期");
return "2";
}
if (Date.parse(d1) - Date.parse(d2) > 0) {
// window.alert("结束日期 小于 开始日期");
return "3";
}
}
//添加一天
function DateAddOneDay(now){
return new Date(Date.parse(now) + (86400000 * 1))
}


踩过,终于又看到新文章了。每次来都能学到新东西,希望下篇文章尽快出来,HOHO。
看不错函数的作用
看不错函数的作用
踩过,终于又看到新文章了。每次来都能学到新东西,希望下篇文章尽快出来,HOHO。
恩,不错,这些方面我的意见在我博客里也写过,可以交流一下。希望看到更好的文章
看不错函数的作用