Appearance
date-formatter 时间格式化器
使用前, 需要先使用 create
创建实例, 才能使用下列函数
js
const dateFormatter = require('date-formatter').create('yyyy-MM-dd hh:mm:ss')
// 默认 yyyy-MM-dd hh:mm:ss, 如果使用默认格式, 无需 create
create 创建实例
参数
参数 | 类型 | 说明 |
---|---|---|
format | string | 格式化模板 |
返回值
object
代码
javascript
const dateFormatter = dateFormatter.create('yyyy-MM-dd hh:mm:ss')
format 格式化时间
参数
参数 | 类型 | 说明 |
---|---|---|
date | date/number | 可空, 日期时间/时间戳 |
返回值
string
日期时间格式化后字符串
代码
js
const nowDate = dateFormatter.format(new Date())
// const defaultDate = dateFormatter.format()
parse 解析日期时间
参数
参数 | 类型 | 说明 |
---|---|---|
date | string | 日期时间字符串 |
返回值
date
时间
代码
javascript
const date = dateFormatter.parse('2025-11-11 11:11:11')