Go Time and Epochs
Go offers extensive support for time and duration via the time package.
1. Basic Time
2. Time Arithmetic
You can compare times or calculate the difference between them.
3. Epoch (Unix Time)
A common way to store time is as a "Unix timestamp"—the number of seconds since January 1, 1970.
4. Durations
time.Duration represents an elapsed period of time.
Why use the time package?
- Precision: Go's
time.Timesupports nanosecond precision. - Monotonicity: Go uses "monotonic clocks" for measuring duration, making it safe from system clock jumps (like Leap Seconds or Daylight Savings changes).
- Standardization: Working with epochs is the standard for APIs and databases.