Standard library / time
time.Time.UnmarshalBinary()
Decode MarshalBinary bytes into receiver; check errors before using the decoded value. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Time) UnmarshalBinary(data []byte) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Encoded bytes to decode. |
Return Value
error
Decode MarshalBinary bytes into receiver; check errors before using the decoded value.
Working Example
Example Snippetgo
package main
import ( "fmt" "time")
func fixed() time.Time { return time.Date(2024, 2, 29, 12, 34, 56, 123000000, time.UTC) }func must(err error) { if err != nil { panic(err) }}func main() { data, err := fixed().MarshalBinary() must(err) var t time.Time must(t.UnmarshalBinary(data)) fmt.Println(t.Equal(fixed()))}