如何解决Go 中 time.Time 的“零”值是多少?

time.Time
fmt.Println(time.Time{})

输出是:

0001-01-01 00:00:00 +0000 UTC

为了完整起见,官方文档明确指出:

Time 类型的零值是 1 月 1 日,第 1 年,00:00:00.000000000 UTC。

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

解决方法