System timer

The time module in python provides various methods and functions related to time.

Elapsed Seconds

The time.time() method returns the current CPU time in seconds (the time since the start of the epoch which is system dependant, but its some date in the past).

import time

    system_seconds = round(time.time())    #round() because a floating point number is returned wheras we want an integer

Elapsed milliseconds

Because the time.time() method returns a floating point second value, all we need to do is multiply it by 1000 and round it off and we have elapsed milliseconds:

    system_milliseconds = round(time.time() * 1000)

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *