alert(getDate()); //当前时间alert(getDate("day", -2)); //前两天的时间alert(getDate("day", 2)); //后两天的时间alert(getDate("month", -2)); //前两个月的时间alert(getDate("month", 2)); //后两个月的时间function getDate(type=null,number=0) {var nowdate = new Date();switch (type) {case "day": //取number天前、后的时间nowdate.setTime(nowdate.getTime() + (24 * 3600 * 1000) * number);var y = nowdate.getFullYear();var m = nowdate.getMonth() + 1;var d = nowdate.getDate();var retrundate = y + '/' + m + '/' + d;break;case "week": //取number周前、后的时间var weekdate = new Date(nowdate + (7 * 24 * 3600 * 1000) * number);var y = weekdate.getFullYear();var m = weekdate.getMonth() + 1;var d = weekdate.getDate();var retrundate = y + '/' + m + '/' + d;break;case "month": //取number月前、后的时间nowdate.setMonth(nowdate.getMonth() + number);var y = nowdate.getFullYear();var m = nowdate.getMonth() + 1;var d = nowdate.getDate();var retrundate = y + '/' + m + '/' + d;break;case "year": //取number年前、后的时间nowdate.setFullYear(nowdate.getFullYear() + number);var y = nowdate.getFullYear();var m = nowdate.getMonth() + 1;var d = nowdate.getDate();var retrundate = y + '/' + m + '/' + d;break;default://取当前时间var y = nowdate.getFullYear();var m = nowdate.getMonth() + 1;var d = nowdate.getDate();var retrundate = y + '/' + m + '/' + d;}return retrundate;}
1000字范文,内容丰富有趣,学习的好帮手!