× Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Lesson 7 Lesson 8 Lesson 9 Lesson 10 Lesson 11 Lesson 12 Lesson 13 Lesson 14 Lesson 15 Lesson 16 Lesson 17 Lesson 18 Lesson 19 Lesson 20 Lesson 21 Lesson 22 Lesson 23 Lesson 24 Lesson 25 Mini Lesson 1 Mini Lesson 2 Mini Lesson 3 Mini Lesson 4 Mini Lesson 5


Lesson 21 - Module Datetime

The datetime module, as the name implies, gives access to a wide range of time related functions. Due to the sheer amount of methods and attributes in this module, I can not cover them all, however there is a complete list of all available methods and attributes here.

One of the most useful methods in this method is the .now() method, which will tell us the current time and date:

import datetime


So we first import the module we want as always, which in our case is the datetime module. Then we use the print() function to output the datetime module's class datetime, which has a method called now(). At the time of creating this lesson, this method outputted 2019-01-07 16:21:38.399280, the current date, time to the nearest nanosecond, very nice precision.

Another useful module from a different class