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()?
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to