本文主要是介绍获取当前日期后五天,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、获取当前日期的时间戳
主要代码:
// 获取当前日期以及后4天 function GetDateStr(AddDayCount) {var _date = new Date();var currentWeek = _date.getDay();_date.setDate(_date.getDate() + AddDayCount); //获取AddDayCount天后的日期 var years = _date.getFullYear();var months = (_date.getMonth() + 1) < 10 ? "0" + (_date.getMonth() + 1) : (_date.getMonth() + 1); //获取当前月份的日期,不足10补0 var days = _date.getDate() < 10 ? "0" + _date.getDate() : _date.getDate(); //获取当前几号,不足10补0 var dates = new Date(years, months - 1, days);var _week;if(dates.getDay() == 0) _week = "周日";if(dates.getDay() == 1) _week = "周一";if(dates.getDay() == 2) _week = "周二";if(dates.getDay() == 3) _week = "周三";if(dates.getDay() == 4) _week = "周四";if(dates.getDay() == 5) _week = "周五";if(dates.getDay() == 6) _week = "周六";return months + "月" + days + "日" + "[" + _week + "]"; } // 默认时间为todays
$("#nowDates").text(GetDateStr(0)); console.log("今天:" + GetDateStr(0)); console.log("明天:" + GetDateStr(1)); console.log("后天:" + GetDateStr(2)); console.log("大后天:" + GetDateStr(3)); console.log("大大后天:" + GetDateStr(4));
这篇关于获取当前日期后五天的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!