dateToEnd() function
将日期转换为指定粒度的结束时间(该粒度区间最后一毫秒)。默认按「日」重置 (23:59:59.999),与原行为一致。
Signature:
typescript
export declare function dateToEnd(value: DateValue, unit?: DateUnit): Date;Parameters
Parameter | Type | Description |
|---|---|---|
value | 时间戳、字符串或 Date 对象 | |
unit | (Optional) 重置粒度,默认 |
Returns:
Date
{Date} 该粒度结束时间的 Date 对象
Example
ts
dateToEnd('2024-06-15 18:30:45.123'); // => 2024-06-15 23:59:59.999(默认,按日)
dateToEnd('2024-06-15 18:30:45.123', 'year'); // => 2024-12-31 23:59:59.999
dateToEnd('2024-02-10 18:30:45.123', 'month'); // => 2024-02-29 23:59:59.999(闰年)
dateToEnd('2024-06-15 18:30:45.123', 'hour'); // => 2024-06-15 18:59:59.999
dateToEnd('2024-06-15 18:30:45.123', 'minute'); // => 2024-06-15 18:30:59.999
dateToEnd('2024-06-15 18:30:45.123', 'second'); // => 2024-06-15 18:30:45.999