日历
This commit is contained in:
42
src/utils/date.ts
Normal file
42
src/utils/date.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
export function getdate(){
|
||||
let now = dayjs()
|
||||
const day = now.date() // 当前天
|
||||
now = now.date(1)
|
||||
const week = now.day(); // 第一天是星期几
|
||||
now = now.month(now.month() + 1);
|
||||
now = now.date(0);
|
||||
const month = now.date(); // 当前月有几天
|
||||
|
||||
|
||||
console.log(day,week,month)
|
||||
let i = 0;
|
||||
let w = 0;
|
||||
|
||||
interface Date{
|
||||
day?: number;
|
||||
list?: Array<any>;
|
||||
}
|
||||
const date: Array<Array<Date>> = [[]];
|
||||
|
||||
while(i < month){
|
||||
|
||||
for(w = 0; w < week; w++){
|
||||
date[0][w] = {};
|
||||
}
|
||||
i++;
|
||||
w = w == 0 ? 1 : w;
|
||||
const zhou = Math.floor((i + w - 1) / 7)
|
||||
const d = {
|
||||
day: i
|
||||
}
|
||||
if(date[zhou] == undefined){
|
||||
date[zhou] = []
|
||||
}
|
||||
date[zhou].push(d)
|
||||
}
|
||||
console.log(date)
|
||||
return date;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user