Files
SnowLuma/.pnpm-store/v11/files/1d/97ab66ca4cb486aaac97860373eba50f22520f4e5887ac45a9fab4cb755150bdc1287c6f38c3fa2985ee3134b17dc4e585997c23cb9a27010f250fa36fb783
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

38 lines
1.6 KiB
Plaintext

import { DateInput } from './types';
/**
* Parses a date from various input types.
* 从各种输入类型中解析日期。
*
* @param input - The input to parse, which can be a string, number, Date, or array of numbers.
* (要解析的输入,可以是字符串、数字、Date 对象或数字数组。)
* @param format - An optional format string that specifies the format of the input string if the input is a string.
* Or A boolean indicating whether the date should be in UTC.
* (可选的格式字符串,指定输入字符串的格式,如果输入是字符串。 或者是布尔值,表示日期是否应为 UTC。)
* @returns A Date object representing the parsed date. (表示解析后日期的 Date 对象。)
* @example
* ```ts
* // 从字符串中解析日期
* const result = parse('20231001123456', 'YYYYMMDDHHmmss');
* console.log(result); // 输出: 2023-10-01T12:34:56.000Z
*
* // 从 ISO 8601 字符串中解析日期
* const isoResult = parse('2023-10-01T12:34:56Z');
* console.log(isoResult); // 输出: 2023-10-01T12:34:56.000Z
*
* // 从数字数组中解析日期
* const arrayResult = parse([2023, 9, 1, 12, 34, 56]);
* console.log(arrayResult); // 输出: 2023-10-01T12:34:56.000Z
*
* // 从数字中解析日期
* const numberResult = parse(1696119296000);
* console.log(numberResult); // 输出: 2023-10-01T12:34:56.000Z
*
* // 从 Date 对象中解析日期
* const dateResult = parse(new Date('2023-10-01T12:34:56Z'));
* console.log(dateResult); // 输出: 2023-10-01T12:34:56.000Z
* ```
*/
export default function parse(input: DateInput | {
isValid: () => any;
}, format?: string): Date;