Golang Datetime Cheatsheet from strftime*
When I initially started working with Go the time format it seemed a bit clunky.
Maybe it’s because it’s a departure from the normal
strftime, but also maybe it’s also because there’s no simple cheatsheet for the various date formatting options like you would see for example in the PHP documentation or in the Python documentation or to use the fancy language of the day, the Rust Chrono crate documentation.
The alternative is to read the source code, specifically the private constants.
That being said, here is a simple cheatsheet between the golang time format and php datetime format to make it easier to switch.
strftime implementations are identical on what they support across various languages (especially if you look at 0 prefixed minutes or seconds), but most of the basic things like
Y for full year are present.
|Description||Example returned values|
|Day of the month, 2 digits with leading zeros|
|A textual representation of a day, three letters|
|Day of the month without leading zeros|
|A full textual representation of the day of the week|
|A full textual representation of a month, such as January or March|
|Numeric representation of a month, with leading zeros|
|A short textual representation of a month, three letters|
|Numeric representation of a month, without leading zeros|
|A full numeric representation of a year, 4 digits||Examples: |
|A two digit representation of a year||Examples: |
|Lowercase Ante meridiem and Post meridiem|
|Uppercase Ante meridiem and Post meridiem|
|12-hour format of an hour without leading zeros|
|24-hour format of an hour without leading zeros|
|12-hour format of an hour with leading zeros|
|24-hour format of an hour with leading zeros - not possible in Golang|
|Minutes with leading zeros|
|Minutes without leading zeros|
|Seconds with leading zeros|
|Seconds without leading zeros|
|Timezone identifier||Examples: |
|Difference to Greenwich time (GMT) without colon between hours and minutes||Example: |
|Difference to Greenwich time (GMT) with colon between hours and minutes||Example: |
|Timezone abbreviation||Examples: |
|Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.|