time package
Go's standard library package for moments, durations, timers and formatting dates, built around the time.Time and time.Duration types.
In more detail
time.Now() returns the current moment as a time.Time; time.Sleep pauses a goroutine for a duration. Keep time and duration distinct: one names a point, the other an interval.
Example
start := time.Now()Related terms
- time.Duration — The Go type for a length of time, such as 2*time.Second, stored as a count of nanoseconds.
- time.Since — The Go function that returns how much time has passed since a given moment, as a time.Duration.
- timer and ticker — Go time values that deliver on a channel later: a timer fires once after a duration, a ticker fires repeatedly at an interval.
- reference time layout — Go's way of describing a date format by writing one fixed example moment, 2006-01-02 15:04:05, in the shape you want.
- UTC — Coordinated Universal Time, the worldwide reference time that does not change with seasons or time zones.
Taught in
- The select Statement — Concurrent Systems Programming with Go
- The time Package — Concurrent Systems Programming with Go