The Time.IsZero method in Go time package checks if the given time is equivalent to the zero time. The zero time refers to January 1, year 1, 00:00:00 UTC.
In this example, we create two time values - t1 and t2. t1 is the zero time while t2 is a specific date/time value. Using the IsZero method, we check if t1 and t2 are equivalent to the zero time.
if t1.IsZero() { fmt.Println("t1 is zero time.") } else { fmt.Println("t1 is not zero time.") }
if t2.IsZero() { fmt.Println("t2 is zero time.") } else { fmt.Println("t2 is not zero time.") } }
In this example, we create two time values - t1 is the current UTC time and t2 is the zero time. Using the IsZero method, we check if t1 and t2 are equivalent to the zero time and print out the respective messages.
Package library: The IsZero method is a function of the time.Time type in the time package in Go.
Golang Time.IsZero - 30 examples found. These are the top rated real world Golang examples of Time.Time.IsZero extracted from open source projects. You can rate examples to help us improve the quality of examples.