format a date in to the format month day, year hour:minute:second.fff am/pm zzz in go

To format a date in the format month day, year hour:minute:second.fff am/pm zzz in Go, you can use the time package's Format function. Here's an example:

main.go
package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Now()
	fmt.Println(t.Format("January 2, 2006 3:04:05.000 pm MST"))
}
135 chars
12 lines

Output:

main.go
May 8, 2021 6:53:32.123 pm UTC
31 chars
2 lines

In the format string, January represents the full month name, 2 represents the day of the month, 2006 represents the year (in the format of the year), 3 represents the hour (in the 12-hour format), 04 represents the minute, 05 represents the second, .000 represents the millisecond, pm represents the AM/PM indicator, and MST represents the timezone abbreviation.

gistlibby LogSnag