You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional
O'Reilly logo

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

The best content for your career. Discover unlimited learning on demand for around $1/day.