獲取當前日期以及三天后的日期


var date=new Date();//獲取當前時間
var year=date.getFullYear();//獲取當前年份
var month=date.getMonth()+1;//獲取當前月
var day=date.getDate();//獲取當前日
var nowTime=newday+'.'+month+'.'+day;//當前日期
console.log(nowTime);打印輸出就是當前日期啦~
 
var runYear=[31,29,31,30,31,30,31,31,30,31,30,31];//獲取閏年所有月份信息
var pingYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];//獲取平年所有月份信息
var newday=day;//定義新日期變量
var newmonth=month;//定義新日期變量
var newyear=year;//定義新日期變量
const DAYS=3;//代表3天后,如果要求四天后,值可直接設為4,依次類推
if (year % 4 == 0 && year % 100 != 0){//判斷平年閏年
console.log(runYear[month-1]);
if (runYear[month - 1] - newday >= DAYS){
newday = newday + DAYS
}
else if (runYear[month-1] - newday < 2&&newmonth!=12){
newmonth=newmonth+1;
newday = DAYS-(runYear[month-1] - newday)
}
else{
newyear=newyear+1;
newmonth=1;
newday = DAYS-(runYear[month-1] - newday)
}
}
else{
if (pingYear[month - 1] - newday >= DAYS) {
console.log(month);
console.log(pingYear[month]);
newday = newday + DAYS
}
else if (pingYear[month-1] - newday < 2 && newmonth != 12) {
newmonth = newmonth + 1;
newday = DAYS-(pingYear[month-1] - newday)
}
else {
newyear = newyear + 1;
newmonth = 1;
newday = DAYS-(pingYear[month-1] - newday)
}
}
 
var willTime=newyear+'.'+newmonth+'.'+newday;//后三天日期
console.log(willTime);//打印輸出就是三天后的日期啦~
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM