爱简收旧衣按件回收前端代码仓库
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.

39 lines
1.2 KiB

  1. "use strict";
  2. function formatTime(timestamp) {
  3. const currentTime = (/* @__PURE__ */ new Date()).getTime();
  4. const diff = (currentTime - timestamp) / 1e3;
  5. if (diff < 60) {
  6. return `${Math.floor(diff)}秒钟前`;
  7. } else if (diff < 60 * 60) {
  8. return `${Math.floor(diff / 60)}分钟前`;
  9. } else if (diff < 60 * 60 * 24) {
  10. return `${Math.floor(diff / 60 / 60)}小时前`;
  11. } else {
  12. let date = new Date(timestamp);
  13. let month = date.getMonth() + 1;
  14. let day = date.getDate();
  15. let hours = date.getHours();
  16. let minutes = date.getMinutes();
  17. if (month < 9)
  18. month = "0" + month;
  19. if (day < 9)
  20. day = "0" + day;
  21. return `${month}-${day} ${hours}:${minutes}`;
  22. }
  23. }
  24. function formatTime2Date(timestamp) {
  25. if (!timestamp) {
  26. return "1970年01月01日";
  27. }
  28. const date = new Date(timestamp);
  29. const year = date.getFullYear();
  30. const month = String(date.getMonth() + 1).padStart(2, "0");
  31. const day = String(date.getDate()).padStart(2, "0");
  32. return `${year}${month}${day}`;
  33. }
  34. const time = {
  35. formatTime,
  36. formatTime2Date
  37. };
  38. exports.time = time;
  39. //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/timeUtils.js.map