| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 补全时分秒,输出 YYYY-MM-DD HH:mm:ss,用于后端 LocalDateTime 字段。
|
| | | * 兼容 Date 对象、"YYYY-MM-DD"、"YYYY-MM-DD HH:mm"、"YYYY-MM-DDTHH:mm:ss" 等输入;
|
| | | * 空值原样返回。
|
| | | */
|
| | | export function toDateTimeString(value) {
|
| | | if (value == null || value === "") return value;
|
| | | if (value instanceof Date) {
|
| | | if (Number.isNaN(value.getTime())) return "";
|
| | | const pad = (num) => String(num).padStart(2, "0");
|
| | | return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(
|
| | | value.getDate()
|
| | | )} ${pad(value.getHours())}:${pad(value.getMinutes())}:${pad(
|
| | | value.getSeconds()
|
| | | )}`;
|
| | | }
|
| | | const [datePart, timePart = ""] = String(value)
|
| | | .trim()
|
| | | .replace("T", " ")
|
| | | .split(/\s+/);
|
| | | const timeUnits = timePart.split(":").filter((unit) => unit !== "");
|
| | | while (timeUnits.length < 3) timeUnits.push("00");
|
| | | const time = timeUnits.map((unit) => unit.padStart(2, "0")).join(":");
|
| | | return `${datePart} ${time}`;
|
| | | }
|
| | |
|
| | | /**
|
| | | * @param {number} time
|
| | | * @param {string} option
|
| | | * @returns {string}
|