Standard library / time

time.Time.UnmarshalJSON()

Decode a quoted RFC3339 timestamp into receiver; null is accepted without changing the value in Go 1.23.2. Expected stdout: '12:00:00\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Time) UnmarshalJSON(data []byte) error

Parameters & Attributes

NameTypeDescription
data[]byteEncoded bytes to decode.

Return Value

error

Decode a quoted RFC3339 timestamp into receiver; null is accepted without changing the value in Go 1.23.2.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func must(err error) {  if err != nil {    panic(err)  }}func main() {  var t time.Time  must(t.UnmarshalJSON([]byte(`"2024-02-29T12:00:00Z"`)))  fmt.Println(t.Format(time.TimeOnly))}
Go Reference