To get today's date in Go, you can use the time.Now()
function to get the current time and date, and then use the Format()
method to format the output as a date string.
Here's an example code snippet:
main.go131 chars12 lines
In this example, we use the Format()
method to format the current time and date as a string in the format YYYY-MM-DD
. The format string uses specific placeholders to specify the year, month, and day components:
2006
: represents the year01
: represents the month02
: represents the dayThis code will output the current date in the format YYYY-MM-DD
.
gistlibby LogSnag