Time ZoneBounds DST Span

Call Time.ZoneBounds around a daylight-saving change to get the exact UTC instants where one zone span ends and the next one starts.

GoData Integrity

Code

gosnippet
30 lines
package main

import (
	"fmt"
	"time"
	_ "time/tzdata"
)

func main() {
	loc, err := time.LoadLocation("America/New_York")
	if err != nil {
		fmt.Println("location failed:", err)
		return
	}

	// daylight-saving (DST) starts on the second Sunday of March in 2026
	dst := time.Date(2026, time.March, 8, 3, 30, 0, 0, loc)
	start, end := dst.ZoneBounds()
	fmt.Println("instant:", dst.Format(time.RFC3339))
	fmt.Println("zone name:", dst.Format("MST"))
	fmt.Println("zone starts:", start.Format(time.RFC3339))
	fmt.Println("zone ends:", end.Format(time.RFC3339))

	// a winter instant falls into the other span of the same location
	winter := time.Date(2026, time.December, 1, 12, 0, 0, 0, loc)
	wStart, wEnd := winter.ZoneBounds()
	fmt.Println("winter zone:", winter.Format("MST"))
	fmt.Println("winter starts:", wStart.Format(time.RFC3339))
	fmt.Println("winter ends:", wEnd.Format(time.RFC3339))
}

How it works

Time ZoneBounds DST Span comes down to the function main.

Error handling is inline: 1 place test err != nil and branch immediately.

What to watch for

  • No external packages — everything relies on the language’s built-in APIs.

Using it

Signature: func main()

Running the file prints labeled results such as location failed:, instant:, zone name: — each operation’s effect is visible in the output.

Key statements

if err != nil {
fmt.Println("location failed:", err)
return
}

Interactive Tools for This Topic

FAQ

What does Time ZoneBounds DST Span print when run?
The script runs standalone; its 8 labeled outputs include `location failed:`, `instant:`, `zone name:`.