Standard library / time
time.LoadLocation()
Load a named IANA time zone from available zoneinfo sources. UTC and Local have special meanings; check errors and provide tzdata if deployment needs it. Expected stdout: '2024-07-01T12:00:00+02:00\n'.
Formal Syntax & Structure
go syntaxgo
func LoadLocation(name string) (*Location, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Location name. |
Return Value
(*Location, error)
Load a named IANA time zone from available zoneinfo sources.
Working Example
Example Snippetgo
package main
import ( "fmt" "time" _ "time/tzdata")
func must(err error) { if err != nil { panic(err) }}func main() { loc, err := time.LoadLocation("Europe/Stockholm") must(err) fmt.Println(time.Date(2024, 7, 1, 12, 0, 0, 0, loc).Format(time.RFC3339))}