Skip to main content
Module 8 · Lesson 4 of 539/50 in the course~12 min
Module lessons (4/5)

The package `time`

Lesson preview5 hands-on exercises readyCourse Go · Module 8 — Essential standard library

time.Now(), durations, parsing with the reference layout 2006-01-02 15:04:05, timers and tickers.

What you'll learn in this lesson

  • Distinguish and combine time.Time and time.Duration using the multiplicative constants (time.Millisecond, time.Second).
  • Measure execution times accurately and monotonically with time.Since.
  • Format and parse dates with the Go reference date (2006-01-02 15:04:05) or with ready constants (time.RFC3339).
  • Create time.NewTicker avoiding resource leaks via defer ticker.Stop().

Overview

The time package clearly separates two concepts that are confused in many application bugs: instants (time.Time, specific points on the timeline) and durations (time.Duration, intervals between two instants).

A time.Time is immutable: methods like Add, UTC, and Truncate return a new value without touching the original.

Sections covered in this lesson

  1. 1time.Time and safe comparisons
  2. 2time.Duration and measurements with time.Since
  3. 3The Go reference layout (2006)
  4. 4Periodic Timers with time.NewTicker
  5. 5Guided practice
  6. 6Check for understanding
Pro Lesson · Module 8 — Essential standard library

Unlock "The package `time`" and the full Course Go curriculum

`time.Now()`, durations, parsing with the reference layout `2006-01-02 15:04:05`, timers and tickers.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Go plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.