the Gravity of Python 2

Ben Finney ben+python at benfinney.id.au
Thu Jan 9 04:03:18 EST 2014


Kushal Kumaran <kushal.kumaran at gmail.com> writes:

> Roy Smith <roy at panix.com> writes:
> > How, in Python, do you get an aware UTC datetime object?
>
> My local copy of the python 3.2.3 docs says:
>
> classmethod datetime.utcnow()
>
>     Return the current UTC date and time, with tzinfo None. This is
>     like now(), but returns the current UTC date and time, as a naive
>     datetime object. An aware current UTC datetime can be obtained by
>     calling datetime.now(timezone.utc). See also now().
>
> Hope this helps.

No, that won't do what was asked. The ‘datetime.datetime.utcnow’
function explicitly returns a naive datetime object, not an aware
datetime object.

-- 
 \       “We must respect the other fellow's religion, but only in the |
  `\       sense and to the extent that we respect his theory that his |
_o__)     wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney




More information about the Python-list mailing list