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