I want a script to produce a readable output that shows how long ago a file was modified. It's quite easy to use Python to obtain the time the file was last modified:
print time.ctime(os.path.getmtime(sys.argv[1]))
This prints out "Sun Jun 16 05:03:37 2013" which is quite nice.
However what I want to print is "4 hours, 3 minutes", and if I run that 3 minutes after that, it will say "4 hours, 6 minutes". etc.
So I can obtain a delta in seconds by subtracting os.path.getmtime(filename)
from time.time()
. It looks like I can use datetime
's timedelta
somehow to do this easily, but the documentation goes into quite a bit of detail and I haven't found a straightforward example yet.