🔵 🔵 🔵


Primary

၊၊||၊|။

❪֎ₐ'❫ Date Format Codes (C) ○|Table|1st|20260602102642-00-⌔

datetime — Basic date and time types — Python 3 documentation#strftime-and-strptime-format-codes

strftime() and strptime() format codes

These methods accept format codes that can be used to parse and format dates:

>>> import datetime as dt
>>> dt.datetime.strptime('31/01/22 23:59:59.999999',
...                      '%d/%m/%y %H:%M:%S.%f')
datetime.datetime(2022, 1, 31, 23, 59, 59, 999999)
>>> _.strftime('%a %d %b %Y, %I:%M%p')
'Mon 31 Jan 2022, 11:59PM'

The following is a list of all the format codes that the 1989 C standard requires, and these work on all platforms with a standard C implementation.

📊 ➺

Several additional directives not required by the C89 standard are included for convenience. These parameters all correspond to ISO 8601 date values.

📊 ➺

These may not be available on all platforms when used with the strftime() method. The ISO 8601 year and ISO 8601 week directives are not interchangeable with the year and week number directives above. Calling strptime() with incomplete or ambiguous ISO 8601 directives will raise a ValueError.

The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation. There are also differences between platforms in handling of unsupported format specifiers.

Added in version 3.6: %G, %u and %V were added.

Added in version 3.12: %:z was added.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •