[Tutor] deleting files that are older than x days old

Mike Hansen mhansen at cso.atmel.com
Wed Jul 13 21:22:11 CEST 2005


> Subject:
> Re: [Tutor] deleting files that are older than x days old
> From:
> Kent Johnson <kent37 at tds.net>
> Date:
> Wed, 13 Jul 2005 13:50:47 -0400
> 
> CC:
> tutor at python.org
> 
> 
> Mike Hansen wrote:
> 
>> How do you convert a time represented in seconds from the epoch into a 
>> datetime object?
> 
> 
> Use datetime.datetime.fromtimestamp():
> 
>  >>> import os, datetime
>  >>> t=os.path.getmtime('build.xml')
>  >>> t
> 1115045692
>  >>> d=datetime.datetime.fromtimestamp(t)
>  >>> d
> datetime.datetime(2005, 5, 2, 10, 54, 52)
> 
> Kent
> 

The docs for fromtimestamp weren't clear to me. i.e. not spelling it out that it 
converts from seconds from the epoch(which must be the POSIX timestamp it's 
referring to).

Thanks! And thanks to the others that replied on how to do this without using 
datetime.

Mike


More information about the Tutor mailing list