javascript获取给定日期后固定时间段以后的日期

//格式化日期函数将20120405格式化成2012-04-05
Date.prototype.format = function(format) // author : meizz
{
   var o =
   {
      "M+" : this.getMonth() + 1, // month
      "d+" : this.getDate(),    // day
      "h+" : this.getHours(),   // hour
      "m+" : this.getMinutes(), // minute
      "s+" : this.getSeconds(), // second
      "q+" : Math.floor((this.getMonth() + 3) / 3),  // quarter
      "S" : this.getMilliseconds() // millisecond
   }
   if(/(y+)/.test(format)) format = format.replace(RegExp.$1,
   (this.getFullYear() + "").substr(4 - RegExp.$1.length));
   for(var k in o)if(new RegExp("(" + k + ")").test(format))
   format = format.replace(RegExp.$1,
   RegExp.$1.length == 1 ? o[k] :
   ("00" + o[k]).substr(("" + o[k]).length));
   return format;
}
//设定一个日期
var _str = '20120506';
var _yyyy = _str.substr(0, 4);
var _mth = _str.substr(4, 2) - 1;
var _dd = _str.substr(6, 2);
//转换Date类型
var _theCurrentDateNoFmt = _date = new Date(_yyyy, _mth, _dd);
//格式化日期格式
var _theCurrentDateFmt = new Date(_yyyy, _mth, _dd).format("yyyy-MM-dd");
//(24 * 60 * 60 * 1000)毫秒后的日期
var _theNextDateTimes = _theCurrentDateNoFmt.getTime() + (24 * 60 * 60 * 1000);
//格式化日期
var _theNextDateDateFmt = new Date(_theNextDateTimes).format("yyyy-MM-dd");
alert(_theNextDateDateFmt);

你可能感兴趣的:(js)