Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unify strftime/ptime notes and refactor code
  • Loading branch information
marat committed Sep 19, 2025
commit ddc75ed650ca2282acceb1a5cb433f92aef555ed
13 changes: 6 additions & 7 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2762,17 +2762,16 @@ Notes:
interchangeable.

(9)
When used with the :meth:`~.datetime.strftime` method, the leading zero is optional
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
``%W``, ``%V`` and ``%y`` (except that on Apple platforms, ``%y`` always produces
a leading zero). Use the ``%-`` flag to produce non-zero-padded output
(for example, ``%-d``).

(10)
When used with the :meth:`~.datetime.strptime` method, the leading zero is optional
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
``%W``, and ``%V``. Format ``%y`` does require a leading zero.

When used with the :meth:`~.datetime.strftime` method, the leading zero is optional
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
Comment thread
mhsmith marked this conversation as resolved.
Outdated
``%W``, ``%V`` and ``%y``. The ``%-`` flag (for example, ``%-d``) will produce
Comment thread
mhsmith marked this conversation as resolved.
Outdated
non-zero-padded output, except for ``%-y`` on Apple platforms, which is still
zero-padded.

(11)
When parsing a month and day using :meth:`~.datetime.strptime`, always
include a year in the format. If the value you need to parse lacks a year,
Expand Down
2 changes: 1 addition & 1 deletion Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _wrap_strftime(object, format, timetuple):
if i < n:
next_ch = format[i]
i += 1
if sys.platform.startswith('win') or sys.platform.startswith('android'):
if sys.platform in ['win32', 'android']:
push(_make_dash_replacement(next_ch, timetuple))
else:
push('%-' + next_ch)
Expand Down
Loading