add FormatText.ts
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import Toolkit from "./Toolkit";
|
||||
|
||||
export default class Time {
|
||||
|
||||
/** 1 秒时间戳 */
|
||||
@@ -104,6 +106,21 @@ export default class Time {
|
||||
return { l, y, d, h, m, s, ms };
|
||||
}
|
||||
|
||||
public static duration(begin?: number, ms?: boolean): string {
|
||||
if (!begin) {
|
||||
return "";
|
||||
}
|
||||
const r = Time.between(new Date(begin), new Date());
|
||||
const parts: string[] = [];
|
||||
Toolkit.doWhere(0 < r.y, () => parts.push(`${r.y} 年`));
|
||||
Toolkit.doWhere(0 < r.d, () => parts.push(`${r.d} 天`));
|
||||
Toolkit.doWhere(0 < r.h, () => parts.push(`${r.h} 小时`));
|
||||
Toolkit.doWhere(0 < r.m, () => parts.push(`${r.m} 分钟`));
|
||||
Toolkit.doWhere(0 < r.s, () => parts.push(`${r.s} 秒`));
|
||||
Toolkit.doWhere(!!ms && 0 < r.ms, () => parts.push(`${r.ms} 毫秒`));
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
public static toMediaTime(seconds: number): string {
|
||||
seconds = Math.floor(seconds);
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
|
||||
Reference in New Issue
Block a user