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) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Encoded 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))}