Lists all supported date and time formatting directives with examples and usage notes.
All directives are fully compatible with the C standard (1989 version).
|
Directive |
Description |
Example |
Notes |
|
%a |
Abbreviated weekday name. |
|
Only the en-US locale is currently supported. |
|
%A |
Full weekday name. |
|
Only the en-US locale is currently supported. |
|
%w |
Weekday as a decimal number, where 0 is Sunday and 6 is Saturday. |
|
None. |
|
%d |
Day of the month as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%b |
Abbreviated month name for the locale. |
|
Only the en-US locale is currently supported. |
|
%B |
Full month name for the locale. |
|
When parsing, a leading zero is not required for the |
|
%m |
Month as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%y |
Year without century as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%Y |
Year with century as a decimal number. |
|
When parsing a year, the valid range is [1, 9999]. If a year is less than 1000, it must be padded with zeros to four digits. For example, 0180 represents the year 180 AD. |
|
%H |
Hour (24-hour clock) as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%I |
Hour (12-hour clock) as a zero-padded decimal number. |
|
When parsing, leading zeros are not required for |
|
%p |
The locale's equivalent of AM or PM. |
|
|
|
%M |
Minute as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%S |
Second as a zero-padded decimal number. |
|
|
|
%f |
Microsecond as a zero-padded decimal number. |
|
When parsing microseconds, the |
|
%z |
UTC offset in the ±HHMM[SS[.ffffff]] format. Returns an empty string for a naive datetime object. |
|
For a naive datetime object, |
|
%Z |
Time zone name. Returns an empty string if the object is naive. |
|
None. |
|
%j |
Day of the year as a zero-padded decimal number. |
|
When parsing, a leading zero is not required for the |
|
%U |
Week number of the year, with Sunday as the first day of the week. Days before the first Sunday of the year are in week 0. |
|
|
|
%W |
Week number of the year, with Monday as the first day of the week. Days before the first Monday of the year are in week 0. |
|
|
|
%c |
The locale's appropriate date and time representation. |
|
Only the en-US locale is currently supported. |
|
%x |
The locale's appropriate date representation. |
|
Only the en-US locale is currently supported. |
|
%X |
The locale's appropriate time representation. |
|
Only the en-US locale is currently supported. |
|
%% |
A literal |
|
None. |
The following non-standard C89 directives are also supported:
|
Directive |
Description |
Example |
Notes |
|
%G |
ISO 8601 week-based year. This is the year that contains the ISO week (%V). |
|
When parsing, |
|
%u |
ISO 8601 weekday as a decimal number, where 1 is Monday. |
|
None. |
|
%V |
ISO 8601 week number of the year (Monday as the first day of the week). |
|
|