0Pricing
Go Academy · Lesson

Time Zones

Work with locations.

Time Carries a Location

Every time.Time has an associated location (time zone). The same instant can be displayed differently depending on the zone.

package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.Date(2026, 5, 30, 12, 0, 0, 0, time.UTC)
    fmt.Println(t.Location())
}

UTC and Local

Two built-in locations are always available:

  • time.UTC for Coordinated Universal Time.
  • time.Local for the machine's local zone.
package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.Date(2026, 5, 30, 12, 0, 0, 0, time.UTC)
    fmt.Println(t.UTC().Hour())
}

All lessons in this course

  1. Time and Duration
  2. Formatting and Parsing
  3. Timers and Tickers
  4. Time Zones
← Back to Go Academy