import os
print(str(os.stat('/home/zarkopafilis/Python/test2.py').st_mtime))
Returns large values like : 1378906011.07
Within 5 seconds I run :
import datetime
now = datetime.datetime.now()
print(str(now.second))
It returns : 1-5(Depending how fast it runs)
How can I check the time that the file was created and see if X seconds have passed by the time script runs?
1378906011.07is the number that represent seconds from epoch (January 1st 1970).You can see the time using
datetime.datetime.fromtimestamp:Use
time.time()to get current date-time as the second:time.time() - os.stat('/home/zarkopafilis/Python/test2.py').st_mtimewill give you passed time.