queenwuli
2020-12-27 cc499362b6eba119792e113796e4da029a70fc6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * 获取某年某月有多少天
 */
export const getOneMonthDays = (year,month)=>{
    month = Number(month);
    const baseMonthsDays = [31,28,31,30,31,30,31,31,30,31,30,31];
    if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
        if(month === 1){
            baseMonthsDays[month] = 29;
        }
    }
    return baseMonthsDays[month];
}
 
/**
 * 获取日期的年月日时分秒
 */
export const getTimeArray = (date)=>{
    const year = date.getFullYear();
    const month = date.getMonth()+1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();
    return [year,month,day,hour,minute,second];
}
/**
 * 小于10的数字前面补0
 */
export const addZero = (num)=>{
    return num < 10 ? '0' + num : num;
}
 
/**
 * 获取当前值在数组中的索引
 */
export const getIndexOfArray = (value,array)=>{
    let index = array.findIndex(item => item == value);
    return index > -1 ? index : 0;
}