summaryrefslogtreecommitdiffstats
path: root/Doc/library/datetime.rst
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-03-01 19:52:07 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-03-01 19:52:07 (GMT)
commite2e178e081a621d2c1fd8ceb65ce7735b3036def (patch)
tree3a6ca0160bf0bc2a357fb3c11806e5a07dd17543 /Doc/library/datetime.rst
parent3de4aae1d06bddb44e157548060ddc4a43ff5657 (diff)
downloadcpython-e2e178e081a621d2c1fd8ceb65ce7735b3036def.zip
cpython-e2e178e081a621d2c1fd8ceb65ce7735b3036def.tar.gz
cpython-e2e178e081a621d2c1fd8ceb65ce7735b3036def.tar.bz2
Closes issue #22791: Improved datetime from timestamp methods documentation.
Original patch by Akira Li.
Diffstat (limited to 'Doc/library/datetime.rst')
-rw-r--r--Doc/library/datetime.rst16
1 files changed, 11 insertions, 5 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 7a9f93c..f82f425 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -759,13 +759,19 @@ Other constructors, all class methods:
:attr:`tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is
out of the range of values supported by the platform C :c:func:`gmtime` function,
and :exc:`OSError` on :c:func:`gmtime` failure.
- It's common for this to be restricted to years in 1970 through 2038. See also
- :meth:`fromtimestamp`.
+ It's common for this to be restricted to years in 1970 through 2038.
+
+ To get an aware :class:`.datetime` object, call :meth:`fromtimestamp`::
+
+ datetime.fromtimestamp(timestamp, timezone.utc)
+
+ On the POSIX compliant platforms, it is equivalent to the following
+ expression::
- On the POSIX compliant platforms, ``utcfromtimestamp(timestamp)``
- is equivalent to the following expression::
+ datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)
- datetime(1970, 1, 1) + timedelta(seconds=timestamp)
+ except the latter formula always supports the full years range: between
+ :const:`MINYEAR` and :const:`MAXYEAR` inclusive.
.. versionchanged:: 3.3
Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp