unixtux 发表于 2013-1-22 22:00:23

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

//格式化日期函数将20120405格式化成2012-04-05Date.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 :   ("00" + o).substr(("" + o).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);
页: [1]
查看完整版本: javascript获取给定日期后固定时间段以后的日期