How to format time in Go

Go introduces a new way to format time. Instead of specifying printf-style placeholders you write your desired format with an actual time.

Example:

t := time.Now().Format("20060102150405")

Here, t will be assigned the current local time as a string, in the format YYYYMMDDHHMMSS

You can also check out some predefined layouts. They use that example time.

via