DateTime():subtract()
从 DateTime 对象中减去指定的时间量。
签名
subtract(amount: number, unit: string): DateTime
参数
| 参数 | 类型 | 描述 |
|---|---|---|
amount | number | 要减去的数量。 |
unit | string | 要减去的时间单位。支持的单位包括:years、year、months、month、weeks、week、days、day、hours、hour、minutes、minute、seconds、second、milliseconds、millisecond |
返回值
- 类型:
DateTime - 当前的
DateTime实例,可用于方法链式调用。
示例
local now = DateTime()
-- 减去 5 天
now:subtract(5, "days")
toast("Date after subtracting 5 days: " .. now:format("yyyy-MM-dd"))
-- 减去 2 个月
now = DateTime() -- 重置
now:subtract(2, "months")
toast("Date after subtracting 2 months: " .. now:format("yyyy-MM-dd"))