Lesson 35 of 60 · Go
Time Package – Parsing, Formatting, and Timers
Duration: 15 minutes
Working with Time
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
now := time.Now()
fmt.Println(now.Format(time.RFC3339))
// Parse ISO‑8601
t, err := time.Parse(time.RFC3339, "2024-03-25T12:34:56Z")
// Timer & After
timer := time.NewTimer(2 * time.Second)
<-timer.C // blocks for 2 s
Tickers (periodic actions)
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
for range ticker.C {
fmt.Println("tick")
}
Timezones
loc, _ := time.LoadLocation("America/New_York")
nyc := now.In(loc)