- Let's begin by importing the datetime module into our namespace and creating a date, time, and datetime object:
>>> import datetime>>> date = datetime.date(year=2013, month=6, day=7)>>> time = datetime.time(hour=12, minute=30, second=19, microsecond=463198)>>> dt = datetime.datetime(year=2013, month=6, day=7, hour=12, minute=30, second=19, microsecond=463198)>>> print("date is ", date)>>> print("time is", time)>>> print("datetime is", dt)date is 2013-06-07 time is 12:30:19.463198 datetime is 2013-06-07 12:30:19.463198
- Let's construct and print out a timedelta object, the other major data type from the datetime module:
>>> td = datetime.timedelta(weeks=2, days=5, hours=10, minutes=20, seconds=6.73, milliseconds=99, microseconds=8) ...