A Better Python strftime / strptime Table

I present two tables that reformat the Python strptime, strftime documentation. The first is a short table with the most useful directives, the second is a longer table with all of the directives. This is easier for me to scan than the native docs. Hopefully it will help others as well.

UnitDirectiveDescriptionExample
YEAR%Y4-digit1970, 1988, 2001, 2013
MONTH%mDecimal zero-padded01, 02, ..., 12
DAY%dDecimal zero-padded01, 02, ..., 31
HOUR%H24-hour clock, zero-padded00, 01, ..., 23
MINUTE%MDecimal zero-padded00, 01, ..., 59
SECOND%SDecimal zero-padded00, 01, ..., 59
TIMEZONE%zUTC offset(empty), +0000, -0400, +1030
ISO format%Y-%m-%dT%H:%M:%S%z

UnitDirectiveDescriptionExample
YEAR%Y4-digit1970, 1988, 2001, 2013
%y2-digit00, 01, ..., 99
MONTH%mDecimal zero-padded01, 02, ..., 12
%bName, localized shortJan, Feb, ..., Dec (en_US);
Jan, Feb, ..., Dez (de_DE)
%BName, localized longJanuary, February, ..., December (en_US);
Januar, Februar, ..., Dezember (de_DE)
DAY%dDecimal zero-padded01, 02, ..., 31
%wDay of week, decimal 0, 1, ..., 6
%aName of day, localized shortSun, Mon, ..., Sat (en_US);
So, Mo, ..., Sa (de_DE)
%AName of day, localized longSunday, Monday, ..., Saturday (en_US);
Sonntag, Montag, ..., Samstag (de_DE)
HOUR%H24-hour clock, zero-padded00, 01, ..., 23
%I12-hour clock, zero-padded01, 02, ..., 12
%pAM/PM, localizedAM, PM (en_US); am, pm (de_DE)
MINUTE%MDecimal zero-padded00, 01, ..., 59
SECOND%SDecimal zero-padded00, 01, ..., 59
%fMicrosecond, decimal zero-padded000000, 000001, ..., 999999
TIMEZONE%zUTC offset(empty), +0000, -0400, +1030
%ZName(empty), UTC, EST, CST
MISC%jDay of year, 3 digit decimal zero-padded001, 002, ..., 366
%UWeek of year, first Sunday, 2 digit decimal zero-padded00, 01, ..., 53
%WWeek of year, first Monday, 2 digit decimal zero-padded00, 01, ..., 53
PRE-FORMATTED%cLocalized pre-formattedTue Aug 16 21:30:00 1988 (en_US);
Di 16 Aug 21:30:00 1988 (de_DE)
%xLocalized date only08/16/88 (None);
08/16/1988 (en_US);
16.08.1988 (de_DE)
%XLocalized time only21:30:00 (en_US);
21:30:00 (de_DE)
%%%%%

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.