time.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 h + ":" + m + ":" + s;
  21. // return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
  22. }
  23. /**
  24. * 月份名称转为英文简写
  25. * @param {*} month :月份
  26. * @returns Jan
  27. */
  28. export function monthChangeEnglish(month) {
  29. if (month == "1" || month == "01") {
  30. return "Jan";
  31. } else if (month == "2" || month == "02") {
  32. return "Feb";
  33. } else if (month == "3" || month == "03") {
  34. return "Mar";
  35. } else if (month == "4" || month == "04") {
  36. return "Apr";
  37. } else if (month == "5" || month == "05") {
  38. return "May";
  39. } else if (month == "6" || month == "06") {
  40. return "Jun";
  41. } else if (month == "7" || month == "07") {
  42. return "Jul";
  43. } else if (month == "8" || month == "08") {
  44. return "Aug";
  45. } else if (month == "9" || month == "09") {
  46. return "Sept";
  47. } else if (month == "10" || month == "10") {
  48. return "Oct";
  49. } else if (month == "11") {
  50. return "Nov";
  51. } else if (month == "12") {
  52. return "Dec";
  53. }
  54. }