You can use the time
package in Go to format a date into the desired format. Here's an example:
main.go136 chars12 lines
In this example, we're getting the current time using time.Now()
and then formatting it using the Format
method with the layout string "2006-01-02 15:04:05.000"
. The layout string uses specific placeholders for different parts of the date and time, such as 2006
for the year, 01
for the month, 02
for the day, 15
for the hour in 24-hour format, 04
for the minute, 05
for the second, and 000
for the microsecond.
gistlibby LogSnag