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.
Code
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
cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.Duration ConverterConvert between human durations like 1w2d3h45m and total seconds, hours, and minutes with negative support.Duration HumanizerTurn a number of seconds into a readable duration such as 1 day, 2 hours, 3 minutes, and show the equivalent in minutes and hours.ISO 8601 Duration ParserParse ISO 8601 durations like PT1H30M into year, month, week, day, and time components with exact or approximate total seconds.
FAQ
- What does Time ZoneBounds DST Span print when run?
- The script runs standalone; its 8 labeled outputs include `location failed:`, `instant:`, `zone name:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.