time - Go 中 time.Time 的 `zero` 值是多少?

标签 time go null

在错误情况下,我尝试返回 nil,这会引发错误:

cannot use nil as type time.Time in return argument

time.Timezero 值是多少?

最佳答案

您应该使用 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.

关于time - Go 中 time.Time 的 `zero` 值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23051973/

相关文章:

java - 设计访问可能为空或 null 的字符串字段的比较器的最佳方法

java - DateTimeFormatter - 解析带有时区的字符串

database - 将单元格格式化为分钟 : seconds in google spreadsheets

go - golang中如何传递变量

来自 go 容器的 Docker 日志(log 和 fmt)在 init 后停止

html - 使用 EL 访问对象属性时进行 null 检查的必要性

python - 在 Python 中循环遍历图像的每个像素的更快方法?

c++ - 测量 CPU/内存消耗

go - 与reflect.StructTag.Get不兼容

c++ - 从普通指针中减去空指针?