Allen's blog Allen's blog
首页
面经
算法 (opens new window)
分类

Allen

前端CV工程师
首页
面经
算法 (opens new window)
分类
  • Javascript

  • TypeScript

  • CSS

  • Vue

  • React

  • 框架和构建工具

  • 工具库

  • 常见业务场景

    • 事件委托
    • 滚动条闪动解决方案
    • 列表拖拽排序
    • linear-gradient背景渐变色
    • 表格组件数据加载,排序等
    • 时间业务
      • 滚动加载
      • 文件下载
    • Bug

    • 项目实战

    • 前端
    • 常见业务场景
    Allen
    2023-02-10
    目录

    时间业务

    参考文章:业务上会用到的时间处理(持续更新) (opens new window)

    Day.js 文档 (opens new window)

    # 时间增加、减少

    时间增加

    dayjs().add(7, 'day')
    
    1

    时间减少

    dayjs().subtract(7, 'day')
    
    1

    支持的单位列表 (opens new window)

    # 获取时间差

    const date1 = dayjs('2019-01-25')
    date1.diff('2018-06-05', 'month', true) // 7.645161290322581  如果要得到一个浮点数,将 true 作为第三个参数传入
    
    1
    2

    # 格式化时间

    dayjs('2019-01-25').format('DD/MM/YYYY')
    
    1

    支持的格式化占位符列表 (opens new window)

    # 判断是否在两个日期之间

    const currentTime = dayjs()
    currentTime.isAfter(dayjs('2011-01-01')) &&
        currentTime.isBefore(dayjs('2033-01-01'))
    
    1
    2
    3

    或者

    dayjs.extend(isBetween)
    dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'))
    // 也可以:
    // dayjs().isBetween('2010-10-19', '2010-10-25', 'month')
    
    1
    2
    3
    4
    上次更新: 2023/12/16, 09:22:46
    表格组件数据加载,排序等
    滚动加载

    ← 表格组件数据加载,排序等 滚动加载→

    最近更新
    01
    rollup使用配置文件rollup.config.ts打包
    12-08
    02
    package.json导出类型
    12-08
    03
    关键问题方案
    11-17
    更多文章>
    Theme by Vdoing | Copyright © 2023-2023 Allen | Github
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式