Standard library / time

time.ParseInLocation()

Parse with loc as the default zone if input omits one; use loc when resolving zone names or offsets. Expected stdout: '2024-02-29T10:00:00Z\n'.

Formal Syntax & Structure

go syntaxgo
func ParseInLocation(layout, value string, loc *Location) (Time, error)

Parameters & Attributes

NameTypeDescription
layoutstringGo reference-time layout string.
valuestringInput timestamp matching the layout.
loc*LocationLocation providing calendar and zone rules.

Return Value

(Time, error)

Parse with loc as the default zone if input omits one; use loc when resolving zone names or offsets.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func must(err error) {  if err != nil {    panic(err)  }}func main() {  loc := time.FixedZone("Plus2", 7200)  t, err := time.ParseInLocation(time.DateTime, "2024-02-29 12:00:00", loc)  must(err)  fmt.Println(t.UTC().Format(time.RFC3339))}
Go Reference