Skip to content

Commit 31d9f5f

Browse files
committed
📝 Add common datetime strings
1 parent 7504e2d commit 31d9f5f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

docs/types/strings/print.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ F-string:
205205
>>> print(f"My name is {uid.capitalize()=}")
206206
My name is uid.capitalize()='Veit'
207207
208-
Formatting date and time formats and IP addresses
209-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208+
Formatting date and time formats
209+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210210

211211
:py:mod:`datetime` supports the formatting of strings using the same syntax as
212-
the :py:meth:`strftime <datetime.datetime.strftime>` method for these objects.
212+
the :py:meth:`datetime.strftime <datetime.datetime.strftime>` method for these
213+
objects.
213214

214215
.. code-block:: pycon
215216
@@ -220,7 +221,26 @@ the :py:meth:`strftime <datetime.datetime.strftime>` method for these objects.
220221
'de_DE.utf-8'
221222
>>> today = datetime.date.today()
222223
>>> print(f"Heute ist {today:%A, %d. %B %Y}.")
223-
Heute ist Dienstag, 25. November 2025.
224+
Heute ist Freitag, 11. Juli 2025.
225+
226+
Conversely, you can also use :meth:`datetime.strptime
227+
<datetime.datetime.strptime>` to convert strings into ``datetime`` objects:
228+
229+
.. code-block:: pycon
230+
231+
>>> today_string = "Fri, 11 Jul 2025 18:46:49"
232+
>>> today = datetime.datetime.strptime(today_string, "%A, %d. %B %Y")
233+
234+
.. csv-table:: Häufige Formatierungen
235+
:header: "Beschreibung", "Beispiel", "Format"
236+
237+
ISO 8601, "2025-07-11T18:46:49", "%Y-%m-%dT%H:%M:%S"
238+
ISO 8601 with time zone, "2025-07-11T18:46:49+0100", "%Y-%m-%dT%H:%M:%S%z"
239+
RFC 2822, "Fr, 11 Jul 2025 18:46:49", "%a, %d %b %Y %H:%M:%S"
240+
RFC 3339 with time zone, "2025-07-11 18:46:49+0100", "%Y-%m-%d %H:%M:%S%z"
241+
242+
Formatting IP addresses
243+
~~~~~~~~~~~~~~~~~~~~~~~
224244

225245
The :py:mod:`ipaddress` module of Python also supports the formatting of
226246
``IPv4Address`` and ``IPv6Address`` objects.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ docs = [
4949
]
5050

5151
[tool.codespell]
52-
ignore-words-list = "ist, symbl, allo"
52+
ignore-words-list = "allo, ist, Juli, symbl"

0 commit comments

Comments
 (0)