You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.5 KiB

  1. export const calcDate = (date1, date2) => {
  2. var date3 = date2 - date1
  3. var days = Math.floor(date3 / (24 * 3600 * 1000))
  4. var leave1 = date3 % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
  5. var hours = Math.floor(leave1 / (3600 * 1000))
  6. var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
  7. var minutes = Math.floor(leave2 / (60 * 1000))
  8. var leave3 = leave2 % (60 * 1000) // 计算分钟数后剩余的毫秒数
  9. var 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) {
  24. let format = 'yyyy-MM-dd hh:mm:ss'
  25. if (date !== 'Invalid Date') {
  26. var 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)) {
  36. format = format.replace(RegExp.$1,
  37. (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  38. }
  39. for (var k in o) {
  40. if (new RegExp('(' + k + ')').test(format)) {
  41. format = format.replace(RegExp.$1,
  42. RegExp.$1.length === 1 ? o[k]
  43. : ('00' + o[k]).substr(('' + o[k]).length))
  44. }
  45. }
  46. return format
  47. }
  48. return ''
  49. }