码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript 时间计算函数

时间:2015-03-30 16:35:09      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

Javascript 时间计算函数

<span style="font-size:18px;">
<span style="font-size:18px;">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;
}</span></span>






Javascript 时间计算函数

标签:

原文地址:http://blog.csdn.net/u010403387/article/details/44750719

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!