experimental.subDuration() 函数
experimental.subDuration()
随时可能更改。
experimental.subDuration()
从时间值中减去持续时间,并返回结果时间值。
已弃用
experimental.subDuration()
已弃用,推荐使用 date.sub()
。
函数类型签名
(d: duration, from: A, ?location: {zone: string, offset: duration}) => time where A: Timeable
有关更多信息,请参阅函数类型签名。
参数
from
(必需) 要从中减去持续时间的时间。
使用绝对时间或相对持续时间。持续时间相对于 now()
。
t
(必需) 要减去的持续时间。
location
用于时间值的位置。
示例
从时间戳中减去六小时
import "experimental"
experimental.subDuration(from: 2019-09-16T12:00:00Z, d: 6h)// Returns 2019-09-16T06:00:00.000000000Z
从相对持续时间中减去六小时
import "experimental"
option now = () => 2022-01-01T12:00:00Z
experimental.subDuration(d: 6h, from: -3h)// Returns 2022-01-01T03:00:00.000000000Z
从一小时前减去两天
时间可以表示为显式时间戳,也可以表示为相对于当前 now
时间的相对时间。subDuration 可以支持任一类型的值。
import "experimental"
option now = () => 2021-12-10T16:27:40Z
experimental.subDuration(from: -1h, d: 2d)// Returns 2021-12-08T15:27:40Z
此页是否对您有帮助?
感谢您的反馈!