1. 程式人生 > >關於js中對當前日期加n天的實現

關於js中對當前日期加n天的實現

function AddDays(dayIn) {
	var date=new Date();
	var myDate=new Date(date.getTime()+dayIn*24*60*60*1000);
	var year=myDate.getFullYear();
	var month=myDate.getMonth()+1;
	var day=myDate.getDate();
	CurrentDate=year+"-";
	if(month>=10)
	{
		CurrentDate=CurrentDate+month+"-";
	}
	else
	{
		CurrentDate=CurrentDate+"0"+month+"-";
	}
	if(day>=10)
	{
		CurrentDate=CurrentDate+day;
	}
	else
	{
		CurrentDate=CurrentDate+"0"+day;
	}
	return CurrentDate;
}


比如當前時間是2000-01-01 加六天就是2000-01-07