Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,7 @@ requires, and these work on all platforms with a standard C implementation.
| | string if the object is | +063415, | |
| | naive). | -030712.345216 | |
+-----------+--------------------------------+------------------------+-------+
| ``%Z`` | Time zone name (empty string | (empty), UTC, EST, CST | |
| ``%Z`` | Time zone name (empty string | (empty), UTC, GMT | \(6) |
| | if the object is naive). | | |
+-----------+--------------------------------+------------------------+-------+
| ``%j`` | Day of the year as a | 001, 002, ..., 366 | \(9) |
Expand Down Expand Up @@ -2533,9 +2533,18 @@ Notes:
In addition, providing ``'Z'`` is identical to ``'+00:00'``.

``%Z``
If :meth:`tzname` returns ``None``, ``%Z`` is replaced by an empty
string. Otherwise ``%Z`` is replaced by the returned value, which must
be a string.
In :meth:`strftime`, ``%Z`` is replaced by an empty string if
:meth:`tzname` returns ``None``; otherwise ``%Z`` is replaced by the
returned value, which must be a string.

:meth:`strptime` only accepts certain values for ``%Z``:

1. any value in ``time.tzname`` for your machine's locale
2. the hard-coded values ``UTC`` and ``GMT``

So someone living in Japan may have ``JST``, ``UTC``, and ``GMT`` as
valid values, but probably not ``EST``. It will raise ``ValueError`` for
invalid values.

.. versionchanged:: 3.2
When the ``%z`` directive is provided to the :meth:`strptime` method, an
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improves documentation of the values that :meth:`datetime.datetime.strptime` accepts for ``%Z``.
Patch by Karl Dubost.