script 时间计算函数


function addZore(x) {if (x < 10) {x = "0" + x;};return x;}//2002-12-18格式

function getCurentDate() {
	var date = new Date();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	month = addZore(month);
	day = addZore(day);
	var today = date.getFullYear() + "-" + month + "-" + day;
	return today;
}

function getMonday(d) {
  d = new Date(d);
  var day = d.getDay(),
      diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
  return new Date(d.setDate(diff));
}

function getThreeMonthLateDate() {
	var begin_date = new Date();
	begin_date.setMonth(begin_date.getMonth() + 3);
	var yyyy = begin_date.getFullYear();
	var mm = begin_date.getMonth() + 1;
	var dd = begin_date.getDate();
	month = addZore(mm);
	day = addZore(dd);
	var end_date = yyyy + "-" + month + "-" + day;
	return end_date;
}

function getThreeMonthLateDateBydate(date_input) {
	var begin_date = new Date(date_input);
	alert(begin_date);
	begin_date.setMonth(begin_date.getMonth() + 3);
	var yyyy = begin_date.getFullYear();
	var mm = begin_date.getMonth() + 1;
	var dd = begin_date.getDate();
	month = addZore(mm);
	day = addZore(dd);
	var end_date = yyyy + "-" + month + "-" + day;
	return end_date;
}

function addDate(days) {
	var d = new Date();
	d.setDate(d.getDate() + days);
	var day = d.getDate();
	var m = d.getMonth() + 1;
	month = addZore(m);
	day = addZore(day);
	return d.getFullYear() + "-" + month + "-" + day;
}

function addDateByDate(sDate1,days){
	var d = new Date(sDate1);
	d.setDate(d.getDate() + days);
	var day = d.getDate();
	var m = d.getMonth() + 1;
	month = addZore(m);
	day = addZore(day);
	return d.getFullYear() + "-" + month + "-" + day;
}