[Go] Check whether a time.Time value is zero

Created on November 29, 2026

You can use the IsZero() method to check whether a time.Time value represents the zero time, January 1, year 1 at midnight UTC. A time.Time variable declared without an initializer starts with that value.

package main

import (
    "fmt"
    "time"
)

func main() {
    var t time.Time
    if t.IsZero() {
        fmt.Println("t is the zero time")
    } else {
        fmt.Println("t has a non-zero time")
    }
}

The program prints:

t is the zero time
Go