zoukankan      html  css  js  c++  java
  • formatTime() 时间戳,返回数据是计算距离现在的时间

     1 const formatTime=function(tiem) {//时间转换
     2   const timestamp = Date.now();
     3   return function (tiem) {
     4     const diff = timestamp - tiem * 1000;
     5     if (diff < 60 * 1000) {
     6       return '刚刚';
     7     } else if (diff < 60 * 60 * 1000) {
     8       return Math.floor(diff / (60 * 1000)) + '分钟前';
     9     } else if (diff < 24 * 60 * 60 * 1000) {
    10       return Math.floor(diff / (60 * 60 * 1000)) + '小时前';
    11     } else {
    12       const createTime = new Date(tiem * 1000);
    13       const Day = createTime.getDate();
    14       const Month = createTime.getMonth() + 1;
    15       const Hour = createTime.getHours();
    16       const Minute = createTime.getMinutes();
    17       function padding(str) {
    18         str = '' + str;
    19         if (str[1]) {
    20           return str;
    21         } else {
    22           return '0' + str;
    23         }
    24       }
    25       return `${padding(Month)}-${padding(Day)} ${padding(Hour)}:${padding(Minute)}`;
    26     }
    27   };
    28 }
  • 相关阅读:
    如何用js判断一个对象是不是Array
    js实现数组去重怎么实现?
    点击一个ul的五个li元素,分别弹出他们的序号,怎么做?
    盒子模型
    13. 查看网络端口、配置网络
    12. 查看系统硬件配置
    11. 系统状态管理
    9. iptables 配置
    10. 编译软件包
    8. 管理软件包
  • 原文地址:https://www.cnblogs.com/linm/p/12376804.html
Copyright © 2011-2022 走看看