get file modification time in mm/dd/yyyy format?
F. Petitjean
littlejohn.75 at news.free.fr
Sat May 7 12:04:15 EDT 2005
Le 7 May 2005 08:23:48 -0700, beliavsky at aol.com a écrit :
> 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.
>
I type
import time
dir(time)
lot of stuff
help(time.localtime)
localtime([seconds]) ->
(tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)
Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
>>> time.localtime(1115478343)
(2005, 5, 7, 17, 5, 43, 5, 127, 1)
it seems to be 7 may 2005 17h 5 minutes 43 seconds
To have such a formatting you have to type help(time.strptime) which
sadly will say
See the library reference manual for formatting codes (same as strftime()).
---
there is no perfect world
More information about the Python-list
mailing list