ADVERTISEMENT
ADVERTISEMENT

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 »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.