add toShortTime
This commit is contained in:
@@ -2,6 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
import Time from "./Time";
|
||||
|
||||
describe("Time", () => {
|
||||
describe("toShortTime", () => {
|
||||
it("test toShortTime", () => {
|
||||
const date = new Date("2027-01-03T04:05:06.789Z");
|
||||
expect(Time.toShortTime(date.getTime())).toBe("05:06");
|
||||
});
|
||||
});
|
||||
describe("between", () => {
|
||||
it("should return time segments between begin and end", () => {
|
||||
const begin = new Date("2026-01-01T00:00:00.000Z");
|
||||
|
||||
@@ -37,6 +37,12 @@ export default class Time {
|
||||
return `${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
public static toShortTime(unix?: number): string {
|
||||
if (!unix) return "";
|
||||
const d = new Date(unix);
|
||||
return `${d.getMinutes().toString().padStart(2, "0")}:${d.getSeconds().toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unix 时间戳转日期和时间
|
||||
*
|
||||
@@ -111,7 +117,7 @@ export default class Time {
|
||||
const milliseconds = remain;
|
||||
const parts: string[] = [];
|
||||
Toolkit.doWhere(0 < years, () => parts.push(`${years} 年`));
|
||||
Toolkit.doWhere(0 < days, () => parts.push(`${days} 日`));
|
||||
Toolkit.doWhere(0 < days, () => parts.push(`${days} 天`));
|
||||
Toolkit.doWhere(0 < hours, () => parts.push(`${hours} 小时`));
|
||||
Toolkit.doWhere(0 < minutes, () => parts.push(`${minutes} 分钟`));
|
||||
Toolkit.doWhere(0 < seconds, () => parts.push(`${seconds} 秒`));
|
||||
|
||||
Reference in New Issue
Block a user