1.0.1 • Published 2 years ago

mg-date-format v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

mg-date-format 包的使用

format 函数 ( 格式化时间 )

示例

const now = new DateFmt().format("yyyy-MM-dd hh:mm:ss");
console.log(now); // 2021-12-29 13:19:12

语法

new DateFmt(p1).format(p2)  // 返回格式化后的时间

/**
 * params
 * p1 需要格式化的时间, 不传默认格式化当前时间(可选)
 * p2 格式化的结果格式, 默认返回 yyyy-MM-dd hh:mm:ss 格式(可选)
 * /


/**
 * yyyy: 年
 * MM: 月
 * dd: 日
 * hh: 小时
 * mm: 分钟
 * ss: 秒
 * /

getRelativeDate 函数 (获取相对时间, 多少天前(后)的时间)

示例

const date = new DateFmt().getRelativeDate(-3, "yyyy-MM-dd");
console.log(date); // 2020-12-12
new DateFmt(date).getRelativeDate(day, str);

/**
 * params
 * date 对比时间, 默认当前 (可选)
 * day 获取相对于 date 多少天前(后) 的时间, day > 0, 多少天后, day < 0 多少天前 (可选)
 * str 获取相对时间 返回的结果 格式, 同 format 函数 格式 (可选)
 * /

getDiffTime 函数 (获取相对于指定时间, 过去了多长时间)

示例

const parse = new DateFmt().getDiffTime("2021-12-29 15:45:00", "hh-mm-ss");
console.log(parse);   // 00-03-52 方法是刚写的...