平安校园
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. export const calcDate = (date1, date2) => {
  2. let date3 = date2 - date1;
  3. let days = Math.floor(date3 / (24 * 3600 * 1000))
  4. let leave1 = date3 % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  5. let hours = Math.floor(leave1 / (3600 * 1000))
  6. let leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
  7. let minutes = Math.floor(leave2 / (60 * 1000))
  8. let leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  9. let seconds = Math.round(date3 / 1000)
  10. return {
  11. leave1,
  12. leave2,
  13. leave3,
  14. days: days,
  15. hours: hours,
  16. minutes: minutes,
  17. seconds: seconds,
  18. }
  19. }
  20. /**
  21. * 日期格式化
  22. */
  23. export function dateFormat(date, format) {
  24. format = format || 'yyyy-MM-dd hh:mm:ss';
  25. if (date !== 'Invalid Date') {
  26. let o = {
  27. "M+": date.getMonth() + 1, //month
  28. "d+": date.getDate(), //day
  29. "h+": date.getHours(), //hour
  30. "m+": date.getMinutes(), //minute
  31. "s+": date.getSeconds(), //second
  32. "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
  33. "S": date.getMilliseconds() //millisecond
  34. }
  35. if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
  36. (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  37. for (let k in o)
  38. if (new RegExp("(" + k + ")").test(format))
  39. format = format.replace(RegExp.$1,
  40. RegExp.$1.length === 1 ? o[k] :
  41. ("00" + o[k]).substr(("" + o[k]).length));
  42. return format;
  43. }
  44. return '';
  45. }