1.0.1 • Published 3 years ago

chat-time-format v1.0.1

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

安装

npm install chat-time-format

导入

const format = require('chat-time-format');

格式化聊天时间

// 调用对象内的chatTimeFormat方法传递当前消息时间戳
// 根据时间如果大于今天0点时间,则返回,凌晨,早上,上午,中午,下午,晚上。
// 根据时间如果小于今天0点时间,大于昨天则返回,昨天几点。
const newTime = format.chatTimeFormat(Date.now());
console.log(newTime);
// 结果 下午14:43

案例 1

const newTime = format.chatTimeFormat(Date.now() - 24 * 60 * 60 * 1000);
console.log(newTime);
// 结果 昨天15:00

案例 2

const newTime = format.chatTimeFormat(Date.now() - 10000 * 60 * 60 * 1000);
console.log(newTime);
// 结果 2021年10月09日 晚上23:01
1.0.1

3 years ago

1.0.0

3 years ago