目录

微信小程序-dayjs使用

微信小程序 dayjs()使用

微信小程序如果要使用dayjs 首先要把dayjs文件下载

方法一

https://i-blog.csdnimg.cn/blog_migrate/65cbf435b5c85eb93d0f5c823b96d903.png#pic_center

https://i-blog.csdnimg.cn/blog_migrate/15ffa544725ebe1672cc5aad783349a5.png#pic_center

在node_modules找到dayjs文件,把名字为dayjs.min.js的文件放入小程序中lib文件夹下(名字随意)

方法二

链接: 提取码: frvu

使用时

// 在所需使用dayjs的js文件引入此文件
import dayjs from '../../lib/dayjs.min.js'
// 然后在js文件中可直接使用
this.data.showTotalTime = dayjs(bg.duration * 1000).format('mm:ss')

附加

格式化时间
dayjs().format(String)
dayjs('2019-01-25').format('[YYYY] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYY 2019-01-25T00:00:00-02:00Z'
dayjs().format('{YYYY} MM-DDTHH:mm:ssZ[Z]') // "{2014} 09-08T08:02:17-05:00Z"
dayjs().year()
dayjs().year(2000)
dayjs().month()
dayjs().month(0)
dayjs().date()
dayjs().date(1)
dayjs().day()
dayjs().day(0)
dayjs().hour()
dayjs().hour(12)
dayjs().minute()
dayjs().minute(59)
dayjs().second()
dayjs().second(1)
毫秒
dayjs().millisecond()
dayjs().millisecond(1)
FormatOutputDescription
YY18两位数的年份
YYYY2018四位数的年份
M1-12月份从 1 开始
MM01-12 月份两位数
MMMJan-Dec简写的月份名称
MMMMJanuary-December完整的月份名称
D1-31月份里的一天
DD01-31 月份里的一天两位数
d0-6 一周中的一天星期天是 0
ddSu-Sa最简写的一周中一天的名称
dddSun-Sat简写的一周中一天的名称
ddddSunday-Saturday一周中一天的名称
H0-23小时
HH00-23小时,两位数
m0-59分钟
mm00-59分钟,两位数
s0-59 秒
ss00-59秒 两位数
SSS000-999秒 三位数
Z+5:00UTC 的偏移量
ZZ+0500UTC 的偏移量,数字前面加上 0
AAMPM
aampm