...

/

Times and Dates

Times and Dates

In this lesson, you'll study the time package and the functions supported by it.

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
svg viewer

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 ...