Standard library / time

time.Time.AppendFormat()

Append formatted time to the supplied byte slice; keep the returned slice because allocation may occur. Expected stdout: 'date=2024-02-29\n'.

Formal Syntax & Structure

go syntaxgo
func (t Time) AppendFormat(b []byte, layout string) []byte

Parameters & Attributes

NameTypeDescription
b[]byteDestination byte slice to append to.
layoutstringGo reference-time layout string.

Return Value

[]byte

Append formatted time to the supplied byte slice; keep the returned slice because allocation may occur.

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 main()            { fmt.Println(string(fixed().AppendFormat([]byte("date="), time.DateOnly))) }
Go Reference