format a date in to the format october 13, 2014 11:13 am in go

main.go
package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Date(2014, time.October, 13, 11, 13, 0, 0, time.UTC)
	fmt.Println(t.Format("January 2, 2006 3:04 pm"))
}
171 chars
12 lines

Output: October 13, 2014 11:13 am

In this code, we use the time package to create a time.Time object with our desired date and time. Then, we use the Format method of the time.Time object to format the date string according to the layout string "January 2, 2006 3:04 pm". The layout string specifies the order and format of the various components of the date and time.

related categories

gistlibby LogSnag