Home »
Golang »
Golang FAQ
What is the zero value for time.Time in Golang?
Learn, what is Zero value for time.Time in Golang, and how to print it?
Submitted by IncludeHelp, on December 01, 2021
What is 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. As this time is unlikely to come up in practice, the IsZero method gives a simple way of detecting a time that has not been initialized explicitly.
How to print Zero value for time.Time?
To get and print the Zero value for time.Time – Call an empty time.Time struct literal, it will return Go's Zero date.
Following statement will print the Zero value of time.Time:
fmt.Println(time.Time{})
Program:
// Golang program to print the
// Zero value for time.Time
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Time{})
}
Output:
0001-01-01 00:00:00 +0000 UTC
Golang FAQ »