Javascript 时间计算函数

页面导航:首页 > 网络编程 > JavaScript > Javascript 时间计算函数

Javascript 时间计算函数

来源: 作者: 时间:2016-02-02 09:59 【

Javascript 时间计算函数function addZore(x) {if (x 10) {x = 0 + x;};return x;} 2002-12-18格式function getCurentDate() {var date = new Date();var month = date getM

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;
}


 

 

 

 

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<