Newbie question
Hans Nowak
ivnowa at hvision.nl
Sun Jun 6 16:27:20 EDT 1999
On 6 Jun 99, mesak1234 at my-deja.com wrote:
> Hi!
> Well, i get problems with getting date from OS....(win32 at this
> moment)... All what i need that to find out date attribute of a file.
> But i even cannot find out what the function i can use to get the real
> time (anything like Date date = new java.util.Date(); ???? :( )
> All functions of 'time library' seem fine but don't help so much...
> Any suggestions?
> Thanks,
> Daniel
To get the date and time attributes of a file, you can use os.stat.
E.g.
os.stat("myfile.txt")
will return a tuple with file info... its size, attributes, etc.
Element -2 (!) is the time used by the file system. You will see a
weird long number like, for example, 928696080; this is because date
and time are packed into one number. Unpack it with the
time.localtime function. This returns another tuple whose elements
are pretty straightforward (year, month, etc).
The system time, on the other hand, can be retrieved with
time.time(). Once again, you'll get one number, which needs to be
unpacked with time.localtime().
For further information, I suggest you study the time module and
os.stat. :)
Veel liefs,
--Hans Nowak (ivnowa at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
More information about the Python-list
mailing list