patterngoCritical
What is the `zero` value for time.Time in Go?
Viewed 0 times
timetheforzerovaluewhat
Problem
In an error condition, I tried to return
What is the
nil, which throws the error:cannot use nil as type time.Time in return argumentWhat is the
zero value for time.Time?Solution
Invoking an empty
The output is:
For the sake of completeness, the official documentation explicitly states:
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
time.Time struct literal will return Go's zero date. Thus, for the following print statement:fmt.Println(time.Time{})The output is:
0001-01-01 00:00:00 +0000 UTCFor the sake of completeness, the official documentation explicitly states:
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
Code Snippets
fmt.Println(time.Time{})0001-01-01 00:00:00 +0000 UTCContext
Stack Overflow Q#23051973, score: 311
Revisions (0)
No revisions yet.