In an error condition, I tried to return nil
, which throws the error:
cannot use nil as type time.Time in return argument
What is the zero
value for time.Time
?
As per the official documentation of Go: The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
Now() function, we can get the current time in Golang by importing time module. Return: Return current date and time. Example #1: In this example, we can see that by using time. Now() function, we are able to get the current date and time.
Duration has a base type int64. Duration represents the elapsed time between two instants as an int64 nanosecond count”. The maximum possible nanosecond representation is up to 290 years.
nil for interfaces, slices, channels, maps, pointers and functions.
You should use the Time.IsZero() function instead:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With