the Gravity of Python 2
Roy Smith
roy at panix.com
Thu Jan 9 09:32:39 EST 2014
In article <mailman.5257.1389274514.18130.python-list at python.org>,
Ben Finney <ben+python at benfinney.id.au> wrote:
> Kushal Kumaran <kushal.kumaran at gmail.com> writes:
>
> > Ben Finney <ben+python at benfinney.id.au> writes:
> >
> > > 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?
> > >>
> > >> classmethod datetime.utcnow()
> > >>
> > >> Return the current UTC date and time, with tzinfo None. [â¦]
> > >
> > > No, that won't do what was asked. The âdatetime.datetime.utcnowâ
> > > function explicitly returns a naive datetime object, not an aware
> > > datetime object.
> >
> > Yes, but the documentation for utcnow explicitly tells you how to get
> > an aware object.
> >
> > "An aware current UTC datetime can be obtained by calling
> > datetime.now(timezone.utc)."
>
> And we come full circle: This is exactly what Roy's original question
> was (IIUC) trying to address. That process is not obvious, and it's not
> simple: it's a series of difficult-to-discover function calls instead of
> just one obvious one.
Yes, exactly. Thank you.
More information about the Python-list
mailing list