// Created on savesnippets.com · https://savesnippets.com/9DEfoy2YRXJbgv package main import ( "fmt" "time" ) func main() { now := time.Now() // Common predefined layouts in the time package fmt.Println(now.Format(time.RFC3339)) // 2025-03-12T14:25:00-05:00 fmt.Println(now.Format(time.RFC3339Nano)) // ...with nanoseconds fmt.Println(now.Format(time.DateOnly)) // 2025-03-12 (Go 1.20+) fmt.Println(now.Format(time.TimeOnly)) // 14:25:00 (Go 1.20+) fmt.Println(now.Format(time.Kitchen)) // 2:25PM // Custom — the reference date is THE format spec fmt.Println(now.Format("2006-01-02 15:04:05")) // ISO local fmt.Println(now.UTC().Format("2006-01-02T15:04:05Z")) // ISO UTC // Parse — same layout convention t, _ := time.Parse(time.RFC3339, "2025-03-12T14:25:00Z") fmt.Println(t) }