experimental.addDuration() 函数
experimental.addDuration()
是 随时可能更改 的实验性功能。
experimental.addDuration()
将持续时间添加到时间值并返回结果时间值。
已弃用
experimental.addDuration()
已弃用,推荐使用 date.add()
。
函数类型签名
(d: duration, to: A, ?location: {zone: string, offset: duration}) => time where A: Timeable
有关更多信息,请参阅函数类型签名。
参数
d
(必需)要添加的持续时间。
to
(必需)要将持续时间添加到的时间。
location
用于时间值的位置。
使用绝对时间或相对持续时间。持续时间相对于 now()
。
示例
向时间戳添加六小时
import "experimental"
experimental.addDuration(d: 6h, to: 2019-09-16T12:00:00Z)// Returns 2019-09-16T18:00:00.000000000Z
向昨天添加一个月
时间可以表示为显式时间戳,也可以表示为相对于当前 now 时间的相对时间。addDuration 可以支持任何类型的值。
import "experimental"
option now = () => 2021-12-10T16:27:40Z
experimental.addDuration(d: 1mo, to: -1d)// Returns 2022-01-09T16:27:40Z
向相对持续时间添加六小时
import "experimental"
option now = () => 2022-01-01T12:00:00Z
experimental.addDuration(d: 6h, to: 3h)// Returns 2022-01-01T21:00:00.000000000Z
此页是否对您有帮助?
感谢您的反馈!