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

Kent Johnson kent37 at tds.net
Wed Jul 13 19:50:47 CEST 2005


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


More information about the Tutor mailing list