summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-25 17:00:40 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-25 17:00:40 (GMT)
commit54afa5504cfbe192f5466ff9edc291b10736dfdd (patch)
tree9193c3d2c892693ba8ea4704ab4769551c7f8480
parentc1935d2abf4ce18031ecbdba0475574260d8256c (diff)
downloadcpython-54afa5504cfbe192f5466ff9edc291b10736dfdd.zip
cpython-54afa5504cfbe192f5466ff9edc291b10736dfdd.tar.gz
cpython-54afa5504cfbe192f5466ff9edc291b10736dfdd.tar.bz2
Issue #2736: Documented how to compute seconds since epoch.
-rw-r--r--Doc/library/datetime.rst16
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index de9ad44..c637f6a 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -721,6 +721,22 @@ Other constructors, all class methods:
It's common for this to be restricted to years in 1970 through 2038. See also
:meth:`fromtimestamp`.
+ On the POSIX compliant platforms, ``utcfromtimestamp(timestamp)``
+ is equivalent to the following expression::
+
+ datetime(1970, 1, 1) + timedelta(seconds=timestamp)
+
+ There is no method to obtain the timestamp from a :class:`datetime`
+ instance, but POSIX timestamp corresponding to a :class:`datetime`
+ instance ``dt`` can be easily calculated as follows. For a naive
+ ``dt``::
+
+ timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)
+
+ And for an aware ``dt``::
+
+ timestamp = (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)) / timedelta(seconds=1)
+
.. classmethod:: datetime.fromordinal(ordinal)