Function: timeTo()
ts
function timeTo(date, options?): string;Relative time from now to a future date — e.g., "in 3 days" / "3 天后". 与现在的相对时间(面向未来),如 "3 天后"。
Accepts Date, string, number (ms timestamp), or nullish. Returns fallback (default '') when input is null/undefined or produces an invalid date.
Parameters
| Parameter | Type |
|---|---|
date | RelativeDateInput |
options | string | RelativeOptions |
Returns
string
Example
ts
timeTo(new Date(Date.now() + 86400000 * 3)) // 'in 3 days' or '3 天后'
timeTo(null) // ''Since
1.0.0