0

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.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364

1 Answers1

0

I found another topic here:

Python format timedelta to string

Looks like there is a limitation of about a hundred million seconds, so I guess I need to handle it differently if the difference is greater than that.

Community
  • 1
  • 1
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • 1
    I think [Adam Jacob Muller's answer](http://stackoverflow.com/a/13756038/1405065) on that question will do exactly what you want. – Blckknght Jun 17 '13 at 01:10