myDataUtil。js


Date.prototype.Format = function(fmt)
{
//author: meizz
var o =
{
"M+" : this.getMonth() + 1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hours
"m+" : this.getMinutes(), //munutes
"s+" : this.getSeconds(), //seconds
"q+" : Math.floor((this.getMonth() + 3) / 3), //floor
"S" : this.getMilliseconds() //milliseconds
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}


Date.prototype.addDays = function(d)
{
this.setDate(this.getDate() + d);
};


Date.prototype.addWeeks = function(w)
{
this.addDays(w * 7);
};


Date.prototype.addMonths= function(m)
{
var d = this.getDate();
this.setMonth(this.getMonth() + m);

if (this.getDate() < d)
this.setDate(0);
};


Date.prototype.addYears = function(y)
{
var m = this.getMonth();
this.setFullYear(this.getFullYear() + y);

if (m < this.getMonth())
{
this.setDate(0);
}
};

function getUpMonth(){
var up = new Date();
up.setMonth(up.getMonth()-1);
var up_year=up.getFullYear();
var up_month=up.getMonth()+1;
var up_day=up.getDate();
if(up_month<10){
up_month="0"+up_month;
}
if(up_day<10){
up_day="0"+up_day;
}
return up_year+"-"+up_month+"-"+up_day;
};
function getThisMonth(){
var now = new Date();
var now_year=now.getFullYear();
var now_month=now.getMonth()+1;
var now_day=now.getDate();
if(now_month<10){
now_month="0"+now_month;
}
if(now_day<10){
now_day="0"+now_day;
}
return now_year+"-"+now_month+"-"+now_day;
};

 

 

 

 

 

 

 

-------------------------

var begin = new Date();
begin.addMonths(-1);
var end=new Date();

if($("input[name=beginDate]").val()==""){
$("input[id='beginDate']").val(begin.Format("yyyy-MM-dd"));
}
if($("input[name=endDate]").val()==""){
$("input[name=endDate]").val(end.Format("yyyy-MM-dd"));
}

 

posted @ 2012-04-01 15:13  七郎  Views(302)  Comments(0Edit  收藏  举报