the Gravity of Python 2
Piet van Oostrum
piet at vanoostrum.org
Thu Jan 9 06:26:21 EST 2014
Kushal Kumaran <kushal.kumaran at gmail.com> writes:
> 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 in Python 2.7 you can just copy the definition of utc from the doc and use that:
from datetime import tzinfo, timedelta, datetime
ZERO = timedelta(0)
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO
utc = UTC()
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list