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