Skip to content

Commit 75c1bd1

Browse files
committed
Add to time docs
1 parent f499dee commit 75c1bd1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Doc/library/time.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ Functions
533533
| ``%Z`` | Time zone name (no characters if no time zone | |
534534
| | exists). Deprecated. [1]_ | |
535535
+-----------+------------------------------------------------+-------+
536+
| ``%:z`` | Behaves exactly as ``%z``, but has a colon | \(5) |
537+
| | separator added between hours, minutes and | |
538+
| | seconds. | |
539+
+-----------+------------------------------------------------+-------+
536540
| ``%G`` | ISO 8601 year (similar to ``%Y`` but follows | |
537541
| | the rules for the ISO 8601 calendar year). | |
538542
| | The year starts with the week that contains | |
@@ -569,6 +573,16 @@ Functions
569573
When used with the :func:`strptime` function, ``%U`` and ``%W`` are only used in
570574
calculations when the day of the week and the year are specified.
571575

576+
(5)
577+
When used with :func:`strftime`, behaves exactly as ``%z``, except that
578+
a colon separator is added between hours, minutes and seconds.
579+
580+
When used with :func:`strptime`, the UTC offset is *required* to have a
581+
colon as a separator between hours, minutes and seconds.
582+
For example, ``'+01:00:00'`` (but *not* ``'+010000'``) will be parsed as
583+
an offset of one hour. In addition, providing ``'Z'`` is identical to
584+
``'+00:00'``.
585+
572586
Here is an example, a format for dates compatible with that specified in the
573587
:rfc:`2822` Internet email standard. [1]_ ::
574588

@@ -586,6 +600,12 @@ Functions
586600
this is also not portable. The field width is normally 2 except for ``%j`` where
587601
it is 3.
588602

603+
.. versionadded:: 3.12
604+
``%:z`` was added for :func:`strftime`
605+
606+
.. versionadded:: next
607+
``%:z`` was added for :func:`strptime`
608+
589609

590610
.. index::
591611
single: % (percent); datetime format
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Support ``%:z`` directive for :meth:`datetime.datetime.strptime`,
2-
:meth:`datetime.time.strptime` and :meth:`time.strptime`.
2+
:meth:`datetime.time.strptime` and :func:`time.strptime`.
33
Patch by Lucas Esposito and Semyon Moroz.

0 commit comments

Comments
 (0)