計算當月天數

2021-08-19 02:38:54 字數 1132 閱讀 1134

let dayarr = ;

let date =newdate();

this.year = date.getyear();

this.month = date.getmonth()+1

;// 當月第一天星期幾

let firstday = (newdate(this.year

,this.month-1

,1)).getday();

// 當月天數&個月天數,需判斷本月與下月是否為同一年、

let theyear =this.month == 12 ?this.year+1 :this.year

;//判斷下個月的年份

let themonth =this.month == 12 ? 1:this.month

;//判斷下個月的月份

// 下個月的第一天-1就是本月的最後一天,即本月的天數

let themonthdays =newdate(newdate(theyear,themonth,

1)-1).getdate();

//本月天數

let lastmonthdays =newdate(newdate(this.year

,this.month-1

,1)-1).getdate();

//上月天數

1

function getcountdays()

12例如, 獲取當前月份(現在是3月)的總天數:

13 getcountdays() // 返回31

js 獲取當月天數

vardate1 moment format yyyy vardate2 moment format mm varnum newdate parseint date1 parseint date2 0 getdate vardate1 newdate getfullyear vardate2 new...

04 根據日期計算當月天數

需求 給出日期,求出其當月份的天數 我們需要用到eomonth函式和day函式,在此解釋一下這兩個函式 eomonth函式 語法 eomonth start date,months 作用 返回一串日期,表示指定月數之前或者之後的月份的最後一天 舉例 當單元格a1內容為 1月1日 輸入公式 eomon...

PHP確定當月天數

28天 date default timezone set prc 預設時區 echo 今天 date y m d time echo 今天 date y m d strtotime 18 june 2008 echo 昨天 date y m d strtotime 1 day echo 明天 da...