How to do it...

  1. 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
  1. 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) ...

Get Pandas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.