util.js 947 B

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