Excel type 'time' conversion to string problem

Matt Gerrans matt_gerrans at hp.com
Wed Jul 10 14:52:53 EDT 2002


I'm not sure if this is the same time object returned in the FindFiles()
tuple, but if it is, it has a Format() method that will return something you
can print:

>>> import win32api
>>> sometime = win32api.FindFiles(r'c:\*.*')[0][1]
>>> sometime.Format()
'06/03/02 19:04:52'

If this doesn't look good to you, you want to format it differently
yourself, you can get at the properties like so:

>>> sometime.year
2002
>>> sometime.month
6
>>> sometime.day
3
>>> sometime.hour
19

And so on.   You could also pack all this into a tuple that looks like what
you get from time.localtime(), then you could use asctime() on it (actually,
maybe there is a way to do that directly?  I don't know...).

- Matt





More information about the Python-list mailing list