What is the value of `zero` for time.Time in Go?

In case of an error, I tried to return nil , which throws an error:

 cannot use nil as type time.Time in return argument 

What is the zero value for time.Time ?

+45
null time go
Apr 14 '14 at 4:29
source share
3 answers

Calling an empty literal struct time.Time will return a null date. Thus, for the following print statement:

 fmt.Println(time.Time{}) 

Output:

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

For completeness, official documentation expressly states:

Zero value of type Time - January 1, year 1, 00: 00: 00.00.000000000 UTC.

+54
Apr 14 '14 at 4:33
source share

Instead, you should use the Time.IsZero () function:

 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. 
+102
Mar 26 '16 at 11:05
source share

Zero value for time. Time 0001-01-01 00:00:00 +0000 UTC See http://play.golang.org/p/vTidOlmb9P

+1
Apr 14 '14 at 4:38
source share



All Articles