TypeScript Library
The Problem
This Solution
Install
yarn add chat-timespan
Usage
; ; timeSpan.formatnew Date"2019-12-01 08:08:08".getTime // 2019年12月01日 08:08timeSpan.formatDate.now - 1000 * 60 * 60 * 2 // 2 小时前timeSpan.formatDate.now - 1000 * 60 * 5 // 5 分钟前timeSpan.formatDate.now - 1000 * 60 * 5 + 1000 // nulltimeSpan.formatDate.now - 1000 * 60 * 2 // 2 分钟前timeSpan.formatDate.now // 刚刚
API
Input :
- timestamp: number | undefined // 时间戳
Output :
c : number | null // 时间字符串