]> granicus.if.org Git - python/commitdiff
Issue #2736: Documented how to compute seconds since epoch.
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 25 Apr 2011 17:00:40 +0000 (13:00 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 25 Apr 2011 17:00:40 +0000 (13:00 -0400)
Doc/library/datetime.rst

index de9ad449b2833f49e69d00f0d0b729b38877b133..c637f6a44d07e3e46e11167e61e6472599e1cca3 100644 (file)
@@ -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)