The first creates a naive datetime
object without a timezone, the second attaches a timezone object, making that object timezone aware.
Both objects will give you the date and time according to UTC.
Quoting from the datetime
module documentation:
An aware object has sufficient knowledge of applicable algorithmic and political time adjustments, such as time zone and daylight saving time information, to locate itself relative to other aware objects. An aware object is used to represent a specific moment in time that is not open to interpretation [1].
A naive object does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like itβs up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality.
Naive and aware objects are not comparable, nor can you perform datetime arithmetic between a naive and an aware datetime object.
Many operations on datetime.datetime
objects differ between the two types; I recommend you search for 'naive' in the documentation. Where operations differ it is due to the extra timezone information present; for example, .utctimetuple()
will return the same value as .timetuple()
but with DST forced off for naive objects, but for an aware object the returned tuple represents UTC time whatever the timezone attached to the object was.