js根據當前日期獲取當前月的第一天和最後一天

2021-09-22 19:58:03 字數 672 閱讀 9035

js根據當前日期獲取當前月的第一天和最後一天

/**

* 獲取當前月的第一天

* @returns

*/function getcurrentmonthfirst(d)

if (day < 10)

return date.getfullyear() + '-' + month + '-' + day;

}/**

* 獲取當前月的最後一天

* @returns

*/function getcurrentmonthlast(d)

if (day < 10)

return date.getfullyear() + '-' + month + '-' + day;

}

呼叫該方法

//獲取當前日期

var currentdate_mon = new date();

//獲取當前月的第一天

var currentmonthfirst = getcurrentmonthfirst(currentdate_mon);

//獲取當前月的最後一天

var currentmonthlast = getcurrentmonthlast(currentdate_mon);

js獲取當前日期

1.date 物件用於處理日期和時間。建立 date 物件的語法 var mydate new date date 物件會自動把當前日期和時間儲存為其初始值。2.引數形式有以下5種 new date month dd,yyyy hh mm ss new date month dd,yyyy new ...

Js獲取當前日期時間

var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31 mydate.get...

JS獲取當前日期時間

var mydate new date var years mydate.getfullyear 從date 物件以四位數字返回年份 var months mydate.getmonth 從date 物件返回月份 0 11 var days mydate.getdate 從date物件返回乙個月中的...