Standard library / time
time.Time.Format()
Format according to Go's reference-time layout, not strftime tokens. The location controls displayed calendar and zone fields. Expected stdout: '29 Feb 2024 12:34\n'.
Formal Syntax & Structure
go syntaxgo
func (t Time) Format(layout string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| layout | string | Go reference-time layout string. |
Return Value
string
Format according to Go's reference-time layout, not strftime tokens.
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(fixed().Format("02 Jan 2006 15:04")) }