根據當前日期獲取本週 本月 本季度相關日期

2021-08-28 14:26:44 字數 1269 閱讀 1256

//獲取時間

var now = new date(); //當前日期

var nowdayofweek = now.getday(); //今天本週的第幾天

var nowday = now.getdate(); //當前日

var nowmonth = now.getmonth(); //當前月

var nowyear = now.getyear(); //當前年

nowyear += (nowyear < 2000) ? 1900 : 0; //

var lastmonthdate = new date(); //上月日期

lastmonthdate.setdate(1);

lastmonthdate.setmonth(lastmonthdate.getmonth()-1);

var lastyear = lastmonthdate.getyear();

var lastmonth = lastmonthdate.getmonth();

//格式化日期:yyyy-mm-dd

function formatdate(date)

if(myweekday < 10)

return (myyear+"-"+mymonth + "-" + myweekday);

}//獲得某月的天數

function getmonthdays(mymonth)

//獲得本季度的開始月份

function getquarterstartmonth()

if(28)

return quarterstartmonth;

}//獲得本週的開始日期

function getweekstartdate()

//獲得本週的結束日期

function getweekenddate()

//獲得本月的開始日期

function getmonthstartdate()

//獲得本月的結束日期

function getmonthenddate()

//獲得上月開始時間

function getlastmonthstartdate()

//獲得上月結束時間

function getlastmonthenddate()

//獲得本季度的開始日期

function getquarterstartdate()

//獲得本季度的結束日期

function getquarterenddate()

js獲取時間 本週 本季度 本月

獲取本週 本季度 本月 上月的開端日期 停止日期 var now new date 當前日期 var nowdayofweek now.getday 今天本週的第幾天 var nowday now.getdate 當前日 var nowmonth now.getmonth 當前月 var nowye...

js獲取時間 本週 本季度 本月

封裝成js檔案 var now new date 當前日期 var nowdayofweek now.getday 今天本週的第幾天 var nowday now.getdate 當前日 var nowmonth now.getmonth 當前月 var nowyear now.getyear 當前...

根據當前時間獲取,本週,本月,本季度等時間段

當前時間 1 d 本週周一 6 本週週日 1 本月月初 1 adddays 1 本月月末 本月月末 0 1 3 adddays 1 本季度初 3 adddays 1 本季度末 new11 本年年初 new 1231 本年年末 至於昨天 明天 上週 上月 上季度 上年度等等,只要adddays add...