JS獲取開始 結束時間

2022-06-10 13:18:13 字數 1722 閱讀 7991

/*

* * 獲取本週、本季度、本月、上月的開始日期、結束日期 */

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(2)

if(5)

if(nowmonth>8)

return

quarterstartmonth;

}

//獲得本週的開始日期

function

getweekstartdate()

//獲得本週的結束日期

function

getweekenddate()

//獲得本月的開始日期

function

getmonthstartdate()

//獲得本月的結束日期

function

getmonthenddate()

//獲得上月開始時間

function

getlastmonthstartdate()

//獲得上月結束時間

function

getlastmonthenddate()

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

function

getquarterstartdate()

//或的本季度的結束日期

function

getquarterenddate()

js獲取本週 上週的開始結束時間

這兩天在做乙個報表體統,其中涉及到了乙個根據本週,上週,本月,上月的時間來進行查詢的問題,在這個我就教一下大家怎麼實現,大家如果有更好的實現方法的,我也希望大家能說出來,我們交流交流.首先呢,我寫了乙個方法,能實現獲取本週,上週的開始時間,並且解決了跨年的問題 在這裡先說明一下,月份,週幾都是從0開...

elmentUI 開始結束時間

正常來說開始結束時間,我們在資料庫裡面設計一般為倆個字段,但是在elmentui元件在開始結束至的時候是用乙個字段顯示,那需要怎麼做呢?解決方法如下 預設 但是這樣就結束了嗎?注意這個只是在選擇的時候將值賦值給開始和結束方法,我們插入到資料庫後,需要重新查詢出來,這個時候需要在query後將開始和結...

mysql獲取昨天的開始時間結束時間

前一天的開始時間 date add str to date date format now y m d y m d h i s interval 1 day 前一天的結束時間 date add date add str to date date format date sub now interva...