在错误的情况下,我试图返回nil,这会引发错误:
cannot use nil as type time.Time in return argument
Run Code Online (Sandbox Code Playgroud)
有什么zero价值time.Time?
gex*_*tra 257
您应该使用Time.IsZero()函数:
func (Time) IsZero
func (t Time) IsZero() bool
IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
Run Code Online (Sandbox Code Playgroud)
zea*_*soi 128
调用空time.Time结构文字将返回Go的零日期.因此,对于以下打印声明:
fmt.Println(time.Time{})
Run Code Online (Sandbox Code Playgroud)
输出是:
0001-01-01 00:00:00 +0000 UTC
Run Code Online (Sandbox Code Playgroud)
为了完整起见,官方文件明确指出:
Time类型的零值是1月1日,第1年00:00:00.000000000 UTC.
| 归档时间: |
|
| 查看次数: |
73189 次 |
| 最近记录: |