date.year() 函数
date.year()
返回指定时间的年份。
函数类型签名
(t: A, ?location: {zone: string, offset: duration}) => int where A: Timeable
有关更多信息,请参阅 函数类型签名。
参数
t
(必需) 要操作的时间。
使用绝对时间、相对持续时间或整数。持续时间相对于 now()
。
location
用于确定时区的位置。默认为 location
选项。
示例
返回时间值的年份
import "date"
date.year(t: 2020-02-11T12:21:03.29353494Z)// Returns 2020
返回相对持续时间的年份
import "date"
option now = () => 2020-02-11T12:21:03.29353494Z
date.year(t: -14y)// Returns 2007
返回当前年份
import "date"
date.year(t: now())
此页是否对您有帮助?
感谢您的反馈!