Here is a sample code to format a given date in the desired format:
main.go191 chars13 lines
Output:
33 chars2 lines
In the above code, we created a variable date
with the current date and time using the time.Now()
function. Then we formatted this date using the Format()
method of time package. We passed the desired string format January 2, 2006 03:04:05.000 pm
inside the Format()
function. The date format is based on a reference date of Jan 2, 2006 3:04:05 PM, the format string uses the values of the reference time to define the output string.
You can change the date as per your requirement.
gistlibby LogSnag