@fir-ui/date-formatter

0.2.8 • Public • Published

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 年 (year) y --> 2018
yy --> 18
yyyy --> 2018
m 月 (month) m --> 5
mm --> 05
d 日 (day) d --> 4
dd --> 04
h 时 (hour) h --> 8
hh --> 08
i 分 (minute) i --> 6
ii --> 06
s 秒 (second) s --> 1
ss --> 01
l 毫秒 (millisecond) l --> 750

Readme

Keywords

none

Package Sidebar

Install

npm i @fir-ui/date-formatter

Weekly Downloads

0

Version

0.2.8

License

MIT

Unpacked Size

10.2 kB

Total Files

7

Last publish

Collaborators

  • funch