【PT.SCC实名制管理系统】24.10.01 -30天,考勤打卡小程序
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.

36 lines
1.0 KiB

4 months ago
  1. function formatTime(timestamp) {
  2. const currentTime = new Date().getTime();
  3. const diff = (currentTime - timestamp) / 1000;
  4. if (diff < 60) {
  5. return `${Math.floor(diff)}秒钟前`;
  6. } else if (diff < 60 * 60) {
  7. return `${Math.floor(diff / 60)}分钟前`;
  8. } else if (diff < 60 * 60 * 24) {
  9. return `${Math.floor(diff / 60 / 60)}小时前`;
  10. } else {
  11. let date = new Date(timestamp);
  12. let month = date.getMonth() + 1;
  13. let day = date.getDate();
  14. let hours = date.getHours();
  15. let minutes = date.getMinutes();
  16. if(month<9) month = "0"+month;
  17. if(day<9) day = "0"+day;
  18. return `${month}-${day} ${hours}:${minutes}`;
  19. }
  20. }
  21. function formatTime2Date(timestamp) {
  22. if(!timestamp){
  23. return "1970年01月01日"
  24. }
  25. const date = new Date(timestamp);
  26. const year = date.getFullYear();
  27. const month = String(date.getMonth() + 1).padStart(2, '0');
  28. const day = String(date.getDate()).padStart(2, '0');
  29. return `${year}${month}${day}`;
  30. }
  31. export default {
  32. formatTime: formatTime,
  33. formatTime2Date: formatTime2Date
  34. }