zoukankan      html  css  js  c++  java
  • 前端时间戳处理去年昨天当天基于dayjs

    方法内代码:参数date为时间戳

     let that = this;
        if (!date) {
          return;
        }
        date = date * 1000
        const IN_DAY = 1000 * 60 * 60 * 24 * 1; //1天
        const Yesterday = 1000 * 60 * 60 * 24 * 2; //昨天
    
        let Y = dayjs(date).year(),
          M = dayjs(date).month(),
          D = dayjs(date).date(),
          // W = dayjs(date).day(),
          W = dayjs(date).format('ddd'),
          H = dayjs(date).hour(),
          Min = dayjs(date).format('mm'),
          nowY = dayjs().year(),
          nowM = dayjs().month(),
          nowD = dayjs().date(),
          timeStr = '';
    
        if (Y < nowY) {
          // 去年
          timeStr = `${y}/${M}/${D} `
        } else {
          if (Y === nowY && M === nowM) {
            // 昨天
            if ((nowD - D) === 1) {
              timeStr = '昨天 '
            } else if (nowD === D) {
              // 当天
              timeStr = ''
            } else {
              // 一周内
              timeStr = W + ' '
            }
          } else {
            timeStr = `${M}/${D} `
          }
        }
        timeStr += `${H}:${Min}`
        return timeStr

    npm地址:https://www.npmjs.com/package/dayjs

    npm安装:

    npm install dayjs --save
    

      

  • 相关阅读:
    赔了多少钱
    datatables使用
    Django开发汇总
    STF的DOCKER搭建
    ubuntu基本
    python 列表、元组、字典、字符串
    Appium环境搭建
    AppCrawler环境搭建
    TASK 总结
    python & jira
  • 原文地址:https://www.cnblogs.com/ncellit/p/13092278.html
Copyright © 2011-2022 走看看