Show Menu
Cheatography

Python Date Time Format (strftime) Cheat Sheet by

Python Date/Time string formatting options

Input: 'Friday, September 7 2021 7:08:14am'

Tag/Code
Output
Descri­ption
%a
Fri
Weekday abbrev­iated 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-p­added decimal number.
%-d
3
Day of the month as a decimal number. (Platform specific)
%b
Sep
Month abbrev­iated name (locale specific).
%B
September
Month full name (locale specific).
%m
09
Month as a zero-p­added decimal number.
%-m
9
Month as a decimal number. (Platform specific)
%y
21
Year without century as a zero-p­added decimal number.
%Y
2021
Year with century as a decimal number.
%H
07
Hour (24-hour clock) as a zero-p­added decimal number.
%-H
7
Hour (24-hour clock) as a decimal number. (Platform specific)
%I
07
Hour (12-hour clock) as a zero-p­added 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-p­added decimal number.
%-M
8
Minute as a decimal number. (Platform specific)
%S
14
Second as a zero-p­added decimal number.
%-S
14
Second as a decimal number. (Platform specific)
%f
000000
Micros­econd as a decimal number, zero-p­added on the left.
%z
+1000
UTC offset in the form ±HHMM[­SS[.ff­ffff]] (empty string if the object is naive).
%Z
Austra­lia­/Me­lbourne
Time zone name (empty string if the object is naive).
%j
246
Day of the year as a zero-p­added 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.
               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          python regex(regular expression) Cheat Sheet

          More Cheat Sheets by doublehelix

          Ubuntu 18.04 Server Configuration Cheat Sheet