Files
GX.O3.WMS/APK/APP_O3/components/opsoft-date-picker/uitls/util.js
T

40 lines
1022 B
JavaScript
Executable File

/**
*
* 获取对应当前时间的数组下标
* year=>years|month=>months|day=>days|hour=>hours|minute=>minuyes|second=>seconds
*/
export const getTimeArrayIndex = (date,startYear)=>{
let year = date.getFullYear();
let month = date.getMonth()+1;
let day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
year = parseInt(year) - parseInt(startYear);
month = parseInt(month) -1;
day = parseInt(day) - 1;
return [year,month,day,hour,minute,second];
}
/**
*
* 根据年,月获取当前月有几天
*/
export const getDays = (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 === 2){
baseMonthsDays[month - 1] = 29;
}
}
return baseMonthsDays[month - 1];
}
/**
* 小于10的数字前面补0
*/
export const addZero = (num)=>{
return num < 10 ? '0' + num : num;
}