0.2.8 • Published 6 years ago
@fir-ui/date-formatter v0.2.8
fir-date-formatter
一个短小精悍的日期时间格式化工具。
📥 安装
Node
yarn add @fir-ui/date-formatter
CDN
<script src="//unpkg.com/@fir-ui/date-formatter"></script>
CDN 引入时,可通过全局变量 firDateFormatter
使用。
🔧 使用
基本用法:传入 Date 实例
var date = new Date()
console.log(
firDateFormatter(
date,
'yy年mm月dd日 hh时ii分ss秒l毫秒'
)
)
输出类似这样:
18年04月12日 06时13分53秒390毫秒
高级用法:自定义占位符及其对应的值
console.log(
firDateFormatter(
{
x: 1000,
y: 2,
z: 1002
},
'x + y = z (i > 0)'
)
)
输出类似这样:
1000 + 2 = 1002 (i > 0)
🔡 日期时间占位符
占位符 | 说明 | 例子 |
---|---|---|
y | 年 (y ear) | y --> 2018 yy --> 18 yyyy --> 2018 |
m | 月 (m onth) | m --> 5 mm --> 05 |
d | 日 (d ay) | d --> 4 dd --> 04 |
h | 时 (h our) | h --> 8 hh --> 08 |
i | 分 (mi nute) | i --> 6 ii --> 06 |
s | 秒 (s econd) | s --> 1 ss --> 01 |
l | 毫秒 (mil lisecond) | l --> 750 |