1. // time 时间戳
    2. let timeDate = (time) => {
    3. let friendlyTime,diffTime;
    4. // 获取当前时间戳
    5. const creatTime = parseInt(new Date().getTime() / 1000);
    6. if(typeof time === "number"){
    7. diffTime = creatTime - time;
    8. }else {
    9. diffTime = creatTime - new Date(time) / 1000;
    10. }
    11. if (diffTime !== '' && diffTime !== null) {
    12. if (diffTime > 60 && diffTime < 60 * 60) {
    13. friendlyTime = parseInt(diffTime / 60) + '分钟前'
    14. } else if (diffTime > 60 * 60 && diffTime <= 60 * 60 * 24) {
    15. friendlyTime = parseInt(diffTime / 60 * 60) + '小时前'
    16. } else if (diffTime > 60 * 60 * 24 && diffTime <= 60 * 60 * 24 * 2) {
    17. //超过1天
    18. friendlyTime = "昨天";
    19. } else if (diffTime > 60 * 60 * 24 * 2 && diffTime <= 60 * 60 * 24 * 3) {
    20. friendlyTime = "前天";
    21. } else if (diffTime > 60 * 60 * 24 * 3 && diffTime <= 60 * 60 * 24 * 7) {
    22. friendlyTime = parseInt(diffTime / 86400) + "天前";
    23. } else if (diffTime > 60 * 60 * 24 * 7 && diffTime <= 60 * 60 * 24 * 7 * 2) {
    24. friendlyTime = "上周";
    25. } else {
    26. if(typeof time === 'number'){
    27. let dateStr = new Date(time * 1000);
    28. let number1 = dateStr.getMonth() + 1
    29. return dateStr.getFullYear() + '-' + number1 + '-' + dateStr.getDate();
    30. }else{
    31. return time;
    32. }
    33. }
    34. }
    35. return friendlyTime
    36. };