You can use the time package in go to format a date to the desired format. The package provides a function Format which can be used to convert a time.Time to a string representation.
Here's an example code snippet:
main.go370 chars21 linesIn the code above, we first create a time.Time object with the current date and time using the Now() function. We then set the timezone to "America/New_York" using the LoadLocation() function. Finally, we convert the time object to the desired format using the Format() function and output the formatted time.
The format string "2006-01-02 15:04:05.000 MST" is a reference to the desired output format. It is important to note that the reference date used in the format string ("2006-01-02 15:04:05.000") is not arbitrary, but rather a specific date used as a reference in go's time package.
The output of the code will be something like:
main.go28 chars2 lines
where EDT is the timezone abbreviation for Eastern Daylight Time.
gistlibby LogSnag