Standard library / time
time.Time.MarshalText()
Encode as RFC3339 text with fractional seconds as needed, without JSON quotes. Check representation errors. Expected stdout: '2024-02-29T12:34:56.123Z\n'.
Formal Syntax & Structure
go syntaxgo
func (t Time) MarshalText() ([]byte, error)Return Value
([]byte, error)
Encode as RFC3339 text with fractional seconds as needed, without JSON quotes.
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().MarshalText(); must(err); fmt.Println(string(data)) }