Times and Dates
Explore the Go time package to manipulate dates and times effectively. Learn to get current time, format dates in custom styles, work with durations and time zones, and measure elapsed time for better application control.
We'll cover the following...
The time Package #
The package time gives us a datatype Time (to be used as a value) and functionality for displaying and measuring time and dates.
The current time is given by time.Now(), and the parts of a time can then be obtained as t.Day(), t.Minute(), and so on. You can make your own time-formats as in:
t := time.Now()
fmt.Printf("%02d.%02d.%4d\n", t.Day(), t.Month(), t.Year()) // e.g.: 29.10.2019
The type Duration represents the elapsed time between two instants as an int64 nanosecond count.
A handy function is Since(t Time) that returns the time elapsed since t.
The type Location maps time instants to the zone in use at that time. UTC represents Universal Coordinated Time.
There ...