毫秒级转换时间

 getFormatTime: function (timestamp) {
    var now = this.getUnix(); //当前时间戳 毫秒级
    var time = timestamp * 1000; //转为毫秒,如果是毫秒可以去除转换
    var today = this.getToDayUnix(); //今天0点时间戳
    var year = this.getYearUnix(); // 今年0点时间戳
    //由于 timestamp 是秒,所以需要乘以1000
    var timer = (now - time) / 1000; //转换为秒级时间戳
    var tip = "";
    if (Math.floor(timer / 60) <= 0) {
      tip = "刚刚";
    } else if (Math.floor(timer / 120) <= 0) {
      tip = "1分钟前";
    } else if (Math.floor(timer / 3600) <= 0) {
      tip = Math.floor(timer / 60) + "分钟前";
    } else if (Math.floor(timer / 7200) <= 0) {
      tip = "1小时前";
    } else if (Math.floor(timer / 86400) <= 0) {
      tip = Math.floor(timer / 3600) + "小时前";
    } else if (timer / 86400 == 1) {
      tip = "昨天";
    } else if (timer / 86400 <= 7) {
      tip = Math.floor(timer / 86400) + "天前";
    } else if (timer / 86400 <= 31) {
      tip = Math.floor(timer / (86400 * 7)) + "周前";
    } else {
      //要注意new Date(time) ,time 是毫秒级
      tip = this.getLastDate(time);
    }
    return tip;
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值