實現當前日期以及一周後的日期和星期幾

2021-10-23 22:49:22 字數 1303 閱讀 9113

上效果圖:

var mydate = new date();  // 獲取當前時間

mydate.getyear(); // 獲取當前年份(2位)

mydate.getfullyear(); // 獲取完整的年份(4位,2020)

mydate.getmonth(); // 獲取當前月份(0-11,0代表1月)

mydate.getdate(); // 獲取當前日份(1-31)

mydate.getday(); // 獲取當前星期x(0-6,0代表星期天)

mydate.gettime(); // 獲取當前時間(從1970.1.1開始的毫秒數)

mydate.gethours(); // 獲取當前小時數(0-23)

mydate.getminutes(); // 獲取當前分鐘數(0-59)

mydate.getseconds(); // 獲取當前秒數(0-59)

mydate.getmilliseconds(); // 獲取當前毫秒數(0-999)

mydate.tolocaledatestring(); // 獲取當前日期

mydate.tolocaletimestring(); // 獲取當前時間

mydate.tolocalestring( ); // 獲取日期與時間

實現今天開始一周後的日期和星期的方法:

getafterdate(n)  else 

}d.setdate(d.getdate() + n)

year = d.getfullyear();

month = d.getmonth() + 1;

day = d.getdate();

days = d.getday();

if (days == 0) else if (days == 1) else if (days == 2) else if (days == 3) else if (days == 4) else if (days == 5) else if (days == 6)

if (n == 0) else

return s;

},// 呼叫函式

this.getafterdate(1) //輸出 週六2020/8/29

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

var date new date 獲取當前時間 var year date.getfullyear 獲取當前年份 var month date.getmonth 1 獲取當前月 var day date.getdate 獲取當前日 var nowtime newday month day 當前日期...

django計算當前日期最近一周日期範圍

匯入包 from django.utils.timezone import now 時間 import datetime 時間 now time datetime.datetime.now 獲取當前時間 day num now time.isoweekday 當前天是這週的第幾天 week star...

JS計算當前日期的周次

函式 function getweek z var now date.parse z now new date now now.sethours 0 now.setminutes 0 now.setseconds 0 var nowmill now.gettime var now day now.g...