Function: clamp()
ts
function clamp(
date,
min,
max): Date;Clamp a date within [min, max]. Returns a clone of the nearest bound if out of range. 将日期限制在 [min, max] 范围内,超出范围时返回对应边界的副本。
Parameters
| Parameter | Type |
|---|---|
date | Date |
min | Date |
max | Date |
Returns
Date
Example
ts
const d = new Date('2026-06-01')
clamp(d, new Date('2026-01-01'), new Date('2026-05-31')) // 2026-05-31Since
1.0.0