A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-July/102003.html below:

[Python-Dev] Curious datetime method

[Python-Dev] Curious datetime methodAlexander Belopolsky alexander.belopolsky at gmail.com
Sat Jul 17 02:24:42 CEST 2010
I always thought that date.today() was a date class method and its
availability as a datetime method was an artifact of datetime
inheritance from date.  I thought datetime.today() would be just the
same as date.today().  It turned out I was wrong.  Instead,
datetime.today() is more like datetime.now().  Almost.

>>> datetime.today()
datetime.datetime(2010, 7, 16, 20, 5, 10, 710143)

The documentation says X.today() is equivalent to
X.fromtimestamp(time.time()) and this is literary true:

>>> class X(datetime):
...     @classmethod
...     def fromtimestamp(cls, t):
...         return "whatever"
...

>>> X.today()
'whatever'

Unlike datetime.now() which gets time directly from OS,
datetime.today() calls time.time(), gets timestamp as float and breaks
it into integer datetime components in fromtimestamp().

This method is slow, relies on various poorly defined float to integer
conversions and cannot produce anything other than local time as a
naive datetime object.

I wonder why would anyone want to use datetime.today() instead of
datetime.now()?
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4