Python Date/Time string formatting options
|
Tag/Code
|
Output
|
Description
|
|
%a
|
Fri
|
Weekday abbreviated name (locale specific).
|
|
%A
|
Friday
|
Weekday full name (locale specific).
|
|
%w
|
4
|
Weekday as a decimal number (where 0 is Sunday and 6 is Saturday).
|
|
%d
|
03
|
Day of the month as a zero-padded decimal number.
|
|
%-d
|
3
|
Day of the month as a decimal number. (Platform specific)
|
|
%b
|
Sep
|
Month abbreviated name (locale specific).
|
|
%B
|
September
|
Month full name (locale specific).
|
|
%m
|
09
|
Month as a zero-padded decimal number.
|
|
%-m
|
9
|
Month as a decimal number. (Platform specific)
|
|
%y
|
21
|
Year without century as a zero-padded decimal number.
|
|
%Y
|
2021
|
Year with century as a decimal number.
|
|
%H
|
07
|
Hour (24-hour clock) as a zero-padded decimal number.
|
|
%-H
|
7
|
Hour (24-hour clock) as a decimal number. (Platform specific)
|
|
%I
|
07
|
Hour (12-hour clock) as a zero-padded decimal number.
|
|
%-I
|
7
|
Hour (12-hour clock) as a decimal number. (Platform specific)
|
|
%p
|
AM
|
AM/PM (locale specific).
|
|
%M
|
08
|
Minute as a zero-padded decimal number.
|
|
%-M
|
8
|
Minute as a decimal number. (Platform specific)
|
|
%S
|
14
|
Second as a zero-padded decimal number.
|
|
%-S
|
14
|
Second as a decimal number. (Platform specific)
|
|
%f
|
000000
|
Microsecond as a decimal number, zero-padded on the left.
|
|
%z
|
+1000
|
UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).
|
|
%Z
|
Australia/Melbourne
|
Time zone name (empty string if the object is naive).
|
|
%j
|
246
|
Day of the year as a zero-padded decimal number.
|
|
%-j
|
246
|
Day of the year as a decimal number. (Platform specific)
|
|
%U
|
35
|
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. |
|
%W
|
35
|
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. |
|
%c
|
Fri Sep 7 2021, 7:08:14am
|
Locale formatted date and time.
|
|
%x
|
03/09/2021
|
Locale formatted date.
|
|
%X
|
07:08:14
|
Locale formatted time.
|
|
%%
|
%
|
The percent '%' chatacter literal.
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.