Python's strftime

List of strftime format codes. Used as a quick reference.

Source Python Documentation

The examples are based on: datetime.datetime(2019, 1, 1, hour=9, minute=15, second=59, microsecond=0, tzinfo=pytz.utc)

Directive Meaning Example
%a Weekday as locale’s abbreviated name. Tue
%A Weekday as locale’s full name. Tuesday
%w Weekday as a decimal number, where 0 is Sunday and 6 is Saturday. 2
%d Day of the month as a zero-padded decimal number. 01
%-d Day of the month as a decimal number. (Platform specific) 1
%b Month as locale’s abbreviated name. Jan
%B Month as locale’s full name. January
%m Month as a zero-padded decimal number. 01
%-m Month as a decimal number. (Platform specific) 1
%y Year without century as a zero-padded decimal number. 19
%Y Year with century as a decimal number. 2019
%H Hour (24-hour clock) as a zero-padded decimal number. 09
%-H Hour (24-hour clock) as a decimal number. (Platform specific) 9
%I Hour (12-hour clock) as a zero-padded decimal number. 09
%-I Hour (12-hour clock) as a decimal number. (Platform specific) 9
%p Locale’s equivalent of either AM or PM. AM
%M Minute as a zero-padded decimal number. 15
%-M Minute as a decimal number. (Platform specific) 15
%S Second as a zero-padded decimal number. 59
%-S Second as a decimal number. (Platform specific) 59
%f Microsecond as a decimal number, zero-padded on the left. 000000
%z UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive). +0000
%Z Time zone name (empty string if the object is naive). UTC
%j Day of the year as a zero-padded decimal number. 001
%-j Day of the year as a decimal number. (Platform specific) 1
%U Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0. 00
%W Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0. 00
%c Locale’s appropriate date and time representation. Tue Jan 1 09:15:59 2019
%x Locale’s appropriate date representation. 01/01/19
%X Locale’s appropriate time representation. 09:15:59
%% A literal '%' character. %

Useful combinations:

Mask Result
%Y-%m-%dT%H:%M:%SZ 2019-01-01T09:15:59Z