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

To format a date in the format month day, year hour:minute am/pm in go, you can use the Time package and pass the desired format string to the 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 PM"))
}
136 chars
12 lines

In this example, we use the time.Now() function to get the current local time. Then, we pass the desired format layout string "January 2, 2006 3:04 PM" to the Format() function to get the formatted date string.

This will output something like:

main.go
March 10, 2021 5:24 PM
23 chars
2 lines

You can customize the format string to get different output formats. You can use the time package documentation to see all the available formats.

gistlibby LogSnag