O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11. Dates and Times

Unsurprisingly, given its antecedents, Go inherits the UNIX notion of time. Time is represented at the low level by the number of seconds since the UNIX Epoch: the start of 1970 UTC. Local time is calculated from this by applying a time zone offset, and can then be converted into something suitable for display, such as a year, month, and day.

Most Go APIs use nanoseconds for time intervals. It’s important to differentiate between time and time intervals. A time is a fixed point relative to some epoc date and depends on things like the current time zone. A time interval, in contrast, is a quantity that makes sense in isolation.

The time package includes two types for representing these two concepts. A Duration represents a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required