在Go语言中,时间包提供了确定和查看时间的函数。 Go语言中的Time.Date()函数用于检查所陈述的“t”出现的年,月和日。此外,此函数在时间包下定义。在这里,您需要导入“time”包才能使用这些函数。
用法:
func (t Time) Date() (year int, month Month, day int)
在这里,“t”是规定的时间。
返回值:它返回指定的“t”的年,月和日。
范例1:
输出:
The stated year is:2020 The stated month is:May The stated day is:6
范例2:
输出:
The stated year is:2021 The stated month is:February The stated day is:3
此处,指定的月份和日期超出了正常范围,但在转换时已将其标准化。