修正日期時區偏移導致顯示少一天的問題
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 57s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-20 10:57:39 +08:00
parent c1d302f03e
commit 239e547a5d
3 changed files with 50 additions and 32 deletions

View File

@@ -21,7 +21,17 @@ export const formatCurrency = (num: number): string => {
*/
export const formatDate = (date: string): string => {
if (!date) return "-";
return new Date(date).toLocaleDateString("zh-TW");
const datePart = date.split("T")[0].split(" ")[0];
const parts = datePart.split("-").map(Number);
if (parts.length < 3 || parts.some(isNaN)) return date;
const [y, m, d] = parts;
const dt = new Date(y, m - 1, d, 12, 0, 0);
const year = dt.getFullYear();
const month = String(dt.getMonth() + 1).padStart(2, '0');
const day = String(dt.getDate()).padStart(2, '0');
return `${year}/${month}/${day}`;
};
/**
@@ -29,12 +39,19 @@ export const formatDate = (date: string): string => {
*/
export const formatDateWithDayOfWeek = (date: string): string => {
if (!date) return "-";
return new Date(date).toLocaleDateString("zh-TW", {
year: "numeric",
month: "2-digit",
day: "2-digit",
weekday: "short",
});
const datePart = date.split("T")[0].split(" ")[0];
const parts = datePart.split("-").map(Number);
if (parts.length < 3 || parts.some(isNaN)) return date;
const [y, m, d] = parts;
const dt = new Date(y, m - 1, d, 12, 0, 0);
const year = dt.getFullYear();
const month = String(dt.getMonth() + 1).padStart(2, '0');
const day = String(dt.getDate()).padStart(2, '0');
const weekDay = dt.toLocaleDateString("zh-TW", { weekday: "short" });
return `${year}/${month}/${day} (${weekDay})`;
};
/**
@@ -54,7 +71,11 @@ export const formatInvoiceNumber = (invoice: string | null | undefined): string
* 獲取當前日期YYYY-MM-DD 格式)
*/
export const getCurrentDate = (): string => {
return new Date().toISOString().split("T")[0];
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
/**