dayjs 实现秒转时分秒格式。

发布时间 2023-07-02 14:55:18作者: 夏秋初

参考

环境

软件/系统 版本 说明
dayjs ^1.11.9

步骤

  1. 安装
yarn add dayjs
  1. 引入
// var dayjs = require('dayjs')
import dayjs from 'dayjs'
// 时间插件
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration);
  1. 使用
// 获取当前年月日
dayjs().format("YYYY-MM-DD");
// 将秒转换为时分秒格式
let s = 60;
dayjs.duration(s, 'seconds').format('HH:mm:ss');