Skip to content

How to Check if a time.Time Variable Is Zero in Golang

Time package has a helper method to check a time.Time variable is zero value or not:

func (t Time) IsZero() bool

Run this simple example to check how it works:

package main

import (
	"fmt"
	"time"
)

func main() {

	var myEmptyTime time.Time

	if myEmptyTime.IsZero() {
		fmt.Println("The variable is zero!")
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *