get file modification time in mm/dd/yyyy format?

Peter Hansen peter at engcorp.com
Sat May 7 11:37:12 EDT 2005


beliavsky at aol.com wrote:
> Using Python 2.4 on Windows, for me the command
> 
> print os.stat("temp.txt")[stat.ST_MTIME]
> 
> gives
> 
> 1115478343 ,
> 
> which is "seconds since the epoch". How can I get the modification time
> in a format such as
> 
> 05/07/2005  11:05 AM
> 
> as in Windows with the dir command? Ideal would be a tuple of 6 values,
> (year,month,day,hour,minute,second). Thanks.

Do you want the time formatted as above, or as a tuple, since you seem 
unclear?

time.strftime('%m/%d/%Y  %H:%M %p', time.localtime(time.time()))

time.localtime(time.time())[:6] would do the latter...

Check the "time" module docs for more.

-Peter



More information about the Python-list mailing list