format a date in to the format month day, year in go

To format a date in Go, use the Time.Format() method, specifying the desired layout. To format a date like "month day, year", use the layout string "January 2, 2006".

main.go
package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.Now()
    formatted := t.Format("January 2, 2006")
    fmt.Println(formatted)
}
155 chars
13 lines

This will output the current date in the desired format, such as "August 11, 2021".

related categories

gistlibby LogSnag