話不多說直接上**
export
function
getmonthdate()
;var now =
newdate()
;//當前日期
var nowmonth = now.
getmonth()
;//當前月
var nowyear = now.
getfullyear()
;//當前年
//本月的開始時間
var monthstartdate =
newdate
(nowyear, nowmonth,1)
;var yy = monthstartdate.
getfullyear()
+"-"
;var mm =
(monthstartdate.
getmonth()
+1<10?
"0"+
(monthstartdate.
getmonth()
+1): monthstartdate.
getmonth()
+1)+
"-";
var dd =
monthstartdate.
getdate()
<10?
"0"+ monthstartdate.
getdate()
: monthstartdate.
getdate()
;//本月的結束時間
var monthenddate =
newdate
(nowyear, nowmonth +1,
0);var
yy= monthenddate.
getfullyear()
+"-"
;varmm=
(monthenddate.
getmonth()
+1<10?
"0"+
(monthenddate.
getmonth()
+1): monthenddate.
getmonth()
+1)+
"-";
vardd
= monthenddate.
getdate()
<10?
"0"+ monthenddate.
getdate()
: monthenddate.
getdate()
; monthdate.start_day = yy + mm + dd;
monthdate.end_day =yy+
mm+dd;
return monthdate
// this.params.start_day = yy + mm + dd; //本月的開始時間
// this.params.end_day = yy + mm + dd; //本月的結束時間
}
這是封裝在乙個js裡面 呼叫如下
先引入
import from "檔案路徑";
然後在呼叫
console.
log(
getmonthdate()
)
日期獲取本月第一天和最後一天
getfullyear 日期物件獲取年份 yyyy getmonth 獲取月份0 11 getdate 獲取一月中的第幾天 1 31 setdate num 傳數字設定本月日期第幾天 newdate year month,day,hours,可以傳字串或數字 newdate fullyear,mon...
獲取本月的第一天和最後一天
獲取本月的第一天和最後一天 var firstdate new date firstdate.setdate 1 第一天var enddate new date firstdate enddate.setmonth firstdate.getmonth 1 enddate.setdate 0 ale...
SQL獲取第一天和最後一天
sql獲取第一天和最後一天 declare dt datetime set dt getdate declare number int set number 3 1 指定日期該年的第一天或最後一天 a.年的第一天 select convert char 5 dt,120 1 1 b.年的最後一天 s...