@fir-ui/date-formatter
v0.2.8
Published
Date formatter for fir-ui
Readme
fir-date-formatter
一个短小精悍的日期时间格式化工具。
📥 安装
Node
yarn add @fir-ui/date-formatterCDN
<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 | 年 (year) | y --> 2018yy --> 18yyyy --> 2018
m | 月 (month) | m --> 5mm --> 05
d | 日 (day) | d --> 4dd --> 04
h | 时 (hour) | h --> 8hh --> 08
i | 分 (minute) | i --> 6ii --> 06
s | 秒 (second) | s --> 1ss --> 01
l | 毫秒 (millisecond) | l --> 750
