The documentation refers to python dates, of these available types.
An object of type time or datetime
may be naive or aware. A datetime
object d
is aware if d.tzinfo
is not None and d.tzinfo.utcoffset(d)
does not return None
. If d.tzinfo
is None
, or if d.tzinfo
is not None
but d.tzinfo.utcoffset(d)
returns None
, d is naive. A time
object t is
aware if t.tzinfo
is not None
and t.tzinfo.utcoffset(None)
does not
return None
. Otherwise, t is naive.
So naive just means it does not have any time zone information.
To make something 'aware' follow this method by unutbu:
In general, to make a naive datetime timezone-aware, use the localize
method:
import datetime
import pytz
unaware = datetime.datetime(2011, 8, 15, 8, 15, 12, 0)
aware = datetime.datetime(2011, 8, 15, 8, 15, 12, 0, pytz.UTC)
now_aware = pytz.utc.localize(unaware)
assert aware == now_aware
For the UTC timezone, it is not really necessary to use localize
since there is no daylight savings time calculation to handle:
now_aware = unaware.replace(tzinfo=pytz.UTC)
works. (.replace
returns a new datetime; it does not modify
unaware
.)
To make it unaware set the timezone to None
.