npm.io
1.0.15 • Published 3 years ago

@xuanmo/datejs

Licence
MIT
Version
1.0.15
Deps
0
Size
15 kB
Vulns
0
Weekly
0
Stars
4

Datejs 简易版时间格式化

安装

yarn add @xuanmo/datejs
or
npm i @xuanmo/datejs

使用

import datejs from '@xuanmo/datejs'

// 默认当前时间,格式:yyyy-MM-dd HH:mm:ss
datejs().format()

// 可传入一个时间作为被转换时间
datejs(new Date('2019-10-10 19:00:00')).format()

// 完整示例
datejs(new Date('2019-11-17 09:00:00')).format('yyyy-MM-dd hh:mm:ss CW')

可格式化规则

规则 描述 是否补零 结果示例
yyyy 2019
MM 09
M Y 9
dd 01
d Y 1
HH 时,24小时制 23
H 时,24小时制 Y 23
hh 时,12小时制 01
h 时,12小时制 Y 1
mm 01
m 1
ss 01
s Y 01
W 1
CW 星期一

Keywords