獲取某年某月每週的開始時間和結束時間

2021-10-05 06:18:31 字數 1297 閱讀 1227

//獲取某年某月每週的開始時間和結束時間

function getinfo(year, month) {

let d = new date();//

// what day is first day

d.setfullyear(year, month-1, 1);

let w1 = d.getday();//某月的第一天是星期幾

console.log("某月的第一天是星期:" + w1);

if (w1 == 0){

w1 = 7;

// total day of month

d.setfullyear(year, month, 0);

let dd = d.getdate();//某月的總天數

console.log("某月的總天數:" + dd);

let d1

// first monday

if (w1 != 1){

d1 = 7 - w1 + 2;

else {

d1 = 1;

let week_count = math.ceil((dd-d1+1)/7);

//let week_count = math.ceil(dd/7);

console.log(year + "年" + month + "月有" + week_count +"周");

for (let i = 0; i < week_count; i++) {

// let monday = d1+i*7;

let monday = d1+i*7;

let sunday = monday + 6;

let starttime = year+"/"+month+"/"+monday;

let endtime;

if (sunday <= dd) {

endtime = year+"/"+month+"/"+sunday;

else {

d.setfullyear(year, month-1, sunday);

endtime = d.getfullyear()+"/"+(d.getmonth()+1)+"/"+d.getdate();

console.log("第"+(i+1)+"周 從" + starttime + " 到 " + endtime + "");

getinfo(2020,4)//2023年4月

說明:這個可以根據需要自行調整。

mysql獲取某周,某月,某年的開始時間和結束時間

一周的開始時間和結束時間 select date format subdate 2020 04 04 23 00 01 weekday 2020 04 04 23 00 01 y m d 00 00 00 date format subdate 2020 04 04 23 00 01 weekday...

獲取某年某月某日的時間開始結束時間

time time year date y 今年 month date m 這個月 day date d 今天 today begin strtotime date y m d time 今天開始時間 today end mktime 23 59,59 month day year 今天結束時間 6...

獲取某年某月某日的時間開始結束時間戳

1.某日開始和結束的時間戳 返回某日開始和結束的時間戳 param int time 某日任意時間的時間戳 return array public static function certainday time 2.今日開始和結束的時間戳 返回今日開始和結束的時間戳 return array pub...