Standard library / time

time.Parse()

Read a time using a reference-time layout. Missing zone defaults to UTC; prefer numeric offsets and check errors. Expected stdout: '60\n'.

Formal Syntax & Structure

go syntaxgo
func Parse(layout, value string) (Time, error)

Parameters & Attributes

NameTypeDescription
layoutstringGo reference-time layout string.
valuestringInput timestamp matching the layout.

Return Value

(Time, error)

Read a time using a reference-time layout.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func must(err error) {  if err != nil {    panic(err)  }}func main() {  t, err := time.Parse(time.RFC3339, "2024-02-29T12:00:00Z")  must(err)  fmt.Println(t.YearDay())}
Go Reference