| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -759,13 +759,19 @@ Other constructors, all class methods: | |||
| 759 | 759 | :attr:`tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is | |
| 760 | 760 | out of the range of values supported by the platform C :c:func:`gmtime` function, | |
| 761 | 761 | and :exc:`OSError` on :c:func:`gmtime` failure. | |
| 762 | - It's common for this to be restricted to years in 1970 through 2038. See also | ||
| 763 | - :meth:`fromtimestamp`. | ||
| 762 | + It's common for this to be restricted to years in 1970 through 2038. | ||
| 763 | + | ||
| 764 | + To get an aware :class:`.datetime` object, call :meth:`fromtimestamp`:: | ||
| 765 | + | ||
| 766 | + datetime.fromtimestamp(timestamp, timezone.utc) | ||
| 767 | + | ||
| 768 | + On the POSIX compliant platforms, it is equivalent to the following | ||
| 769 | + expression:: | ||
| 764 | 770 | ||
| 765 | - On the POSIX compliant platforms, ``utcfromtimestamp(timestamp)`` | ||
| 766 | - is equivalent to the following expression:: | ||
| 771 | + datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp) | ||
| 767 | 772 | ||
| 768 | - datetime(1970, 1, 1) + timedelta(seconds=timestamp) | ||
| 773 | + except the latter formula always supports the full years range: between | ||
| 774 | + :const:`MINYEAR` and :const:`MAXYEAR` inclusive. | ||
| 769 | 775 | ||
| 770 | 776 | .. versionchanged:: 3.3 | |
| 771 | 777 | Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1393,7 +1393,7 @@ def fromtimestamp(cls, t, tz=None): | |||
| 1393 | 1393 | ||
| 1394 | 1394 | @classmethod | |
| 1395 | 1395 | def utcfromtimestamp(cls, t): | |
| 1396 | - "Construct a UTC datetime from a POSIX timestamp (like time.time())." | ||
| 1396 | + """Construct a naive UTC datetime from a POSIX timestamp.""" | ||
| 1397 | 1397 | t, frac = divmod(t, 1.0) | |
| 1398 | 1398 | us = int(frac * 1e6) | |
| 1399 | 1399 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5020,8 +5020,7 @@ static PyMethodDef datetime_methods[] = { | |||
| 5020 | 5020 | ||
| 5021 | 5021 | {"utcfromtimestamp", (PyCFunction)datetime_utcfromtimestamp, | |
| 5022 | 5022 | METH_VARARGS | METH_CLASS, | |
| 5023 | - PyDoc_STR("timestamp -> UTC datetime from a POSIX timestamp " | ||
| 5024 | - "(like time.time()).")}, | ||
| 5023 | + PyDoc_STR("Construct a naive UTC datetime from a POSIX timestamp.")}, | ||
| 5025 | 5024 | ||
| 5026 | 5025 | {"strptime", (PyCFunction)datetime_strptime, | |
| 5027 | 5026 | METH_VARARGS | METH_CLASS, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments