This quickie will give you a small introduction to the time module: Get the current time, local time and pausing your programs.
Manipulation, converting and showing time with python is really easy thanks to the time module. Simply
import time and we can get started:
With the time module you can simply use
time.time() to return the current time in seconds since the Unix epoch (1970-01-01T00:00:00Z). Example:
To get the local time, use
time.localtime(). This will return a time-tuple. Which can be made readable with a simple additional line:
time.asctime(). As a result, you get the example down below:
It’s actually the localtime of the server it is running on in the example above. You could also pass time in seconds (since the Unix epoch) and turn it to local time with this function.
The time module can do more of course. It also can put your process to sleep :P. Use
time.sleep(4). This will pause your sequence for 4 seconds.
You can learn python with several books. Here’s a couple of them down below: