Overview:
datetime module in Python provides classes and constants pertaining to date, time, timezone and time differences.
The classes in datetime module represent two types of objects. They are
- Naive objects
- Aware objects
1. Naive objects:
- Naive time objects contain a time quantity but do not tell which timezone the time quantity belongs to.
- Naive objects for example can contain 10 AM, but in which time zone is not mentioned.
- Naive objects do not even assume whether the time is UTC or not.
- Nor they convey what is the timezone offset from UTC for the time mentioned.
- It is up to the program that processes the native time objects to interpret a meaning for the time associated with Naive Objects.
- One Program can process a naive object as CST whereas another program can process a naive object with the same time quantity as EST.
- The date and the timedelta classes provide the naive objects in Python.
2. Aware Objects
- The aware objects provided by the datetime module classes contain time quantity as well as the time zone information.
- The time zone information tells what is the time difference between UTC and the time represented.
- The time zone information also contains the name of the time zone.
- The classes datetime and time provide time zone aware objects in Python.
List of classes in datetime module:
Class Name |
Description |
Is Time Zone Aware? |
|
Not time zone Aware. Produce naive objects. |
|
|
Time zone aware. |
|
|
Time zone aware. |
|
timedelta |
Objects of this class are used to represent time difference between two time quantities. |
Not time zone Aware. Produce naive objects. |
tzinfo |
Abstract base class for objects that represent a time zone. |
Concrete classes of tzinfo provide time zone information.
|
timezone |
|
|