Date Time Functions
Example 1: Get Current Date and Time
import datetime
datetime_object = datetime.datetime.now()
print(datetime_object)Example 2: Get Current Date
import datetime
date_object = datetime.date.today()
print(date_object)Example 3: Date object to represent a date
import datetime
d = datetime.date(2019, 4, 13)
print(d)Example 4: Get current date
Example 5: Get date from a timestamp
Example 6: Print today's year, month and day
Example 7: Time object to represent time
Example 8: Print hour, minute, second and microsecond
Example 9: Python datetime object
Example 10: Print year, month, hour, minute and timestamp
Example 11: Difference between two dates and times
Example 12: Difference between two timedelta objects
Example 13: Printing negative timedelta object
Handling timezone in Python
Last updated