Time and date

Python can get the system time using the module time.
To use this module type:

Time is not part of the standard library.


In the example below we output the day,month and year followed by the current time.

The first line returns all variables required (year,month,day,hour,minute).

The function time.time() returns ticks. Ticks are system ticks every computer holds.

As humans we don’t read system ticks, this needs to be converted to actual human time.
The function localtime() converts these ticks into the actual human readable values.

Convert with:

Type the program shown below and run it:

Study drill

Try the exercises below

After completing these continue with the next exercise.