time.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * 时间戳格式化
  3. * 时间戳为10位需*1000,时间戳为13位的话不需乘1000
  4. * @param {*} time:时间戳
  5. * @returns '1970-01-01 08:00:00'
  6. */
  7. export function timestampToTime(time) {
  8. var date = new Date(time * 1000)
  9. let y = date.getFullYear()
  10. let MM = date.getMonth() + 1
  11. MM = MM < 10 ? ('0' + MM) : MM
  12. let d = date.getDate()
  13. d = d < 10 ? ('0' + d) : d
  14. let h = date.getHours()
  15. h = h < 10 ? ('0' + h) : h
  16. let m = date.getMinutes()
  17. m = m < 10 ? ('0' + m) : m
  18. let s = date.getSeconds()
  19. s = s < 10 ? ('0' + s) : s
  20. return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
  21. }
  22. /**
  23. * 月份名称转为英文简写
  24. * @param {*} month :月份
  25. * @returns Jan
  26. */
  27. export function monthChangeEnglish(month) {
  28. if (month == '1' || month == '01') {
  29. return 'Jan'
  30. } else if (month == '2' || month == '02') {
  31. return 'Feb'
  32. } else if (month == '3' || month == '03') {
  33. return 'Mar'
  34. } else if (month == '4' || month == '04') {
  35. return 'Apr'
  36. } else if (month == '5' || month == '05') {
  37. return 'May'
  38. } else if (month == '6' || month == '06') {
  39. return 'Jun'
  40. } else if (month == '7' || month == '07') {
  41. return 'Jul'
  42. } else if (month == '8' || month == '08') {
  43. return 'Aug'
  44. } else if (month == '9' || month == '09') {
  45. return 'Sept'
  46. } else if (month == '10' || month == '10') {
  47. return 'Oct'
  48. } else if (month == '11') {
  49. return 'Nov'
  50. } else if (month == '12') {
  51. return 'Dec'
  52. }
  53. }