From 3ae2c0e7d1ecd3e459a386a2c4a25012ceec45d6 Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 9 May 2026 15:32:58 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=A0=B9=E6=8D=AE=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/wallet/wallet-logs-block.tsx | 3 ++- src/lib/format-local-datetime.ts | 26 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/lib/format-local-datetime.ts diff --git a/src/features/wallet/wallet-logs-block.tsx b/src/features/wallet/wallet-logs-block.tsx index f50cbb2..48f0192 100644 --- a/src/features/wallet/wallet-logs-block.tsx +++ b/src/features/wallet/wallet-logs-block.tsx @@ -9,6 +9,7 @@ import { CardTitle, } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; +import { formatLocalDateTime } from "@/lib/format-local-datetime"; import { formatMinorAsCurrency } from "@/lib/money"; import type { WalletLogItem, WalletLogsData } from "@/types/api/wallet-logs"; @@ -153,7 +154,7 @@ export function LogRow({

- {item.created_at?.replace("T", " ").slice(0, 19) ?? "—"}{" "} + {formatLocalDateTime(item.created_at)}{" "} · {txnStatusLabel(item.status)} diff --git a/src/lib/format-local-datetime.ts b/src/lib/format-local-datetime.ts new file mode 100644 index 0000000..872a074 --- /dev/null +++ b/src/lib/format-local-datetime.ts @@ -0,0 +1,26 @@ +function pad2(n: number): string { + return String(n).padStart(2, "0"); +} + +/** + * 将接口 ISO 8601 时间格式化为浏览器 **本地时区** 下的 `YYYY-MM-DD HH:mm:ss`。 + * + * 避免对原始字符串仅 `slice(0,19)`(易把 UTC 刻度误当本地钟面)。 + */ +export function formatLocalDateTime(iso: string | null | undefined): string { + if (iso == null || iso === "") { + return "—"; + } + const ms = Date.parse(iso); + if (Number.isNaN(ms)) { + return "—"; + } + const date = new Date(ms); + const y = date.getFullYear(); + const m = pad2(date.getMonth() + 1); + const d = pad2(date.getDate()); + const h = pad2(date.getHours()); + const min = pad2(date.getMinutes()); + const s = pad2(date.getSeconds()); + return `${y}-${m}-${d} ${h}:${min}:${s}`; +}