Date formats
Michael P. Reilly
arcege at shore.net
Thu Jun 10 14:56:15 EDT 1999
mike milliger <milliger at ausinfo.com> wrote:
: I read the documentation in the Python Reference Library (6.3) on time
: access and conversions and chapter 8 in programming python, yet I can't
: figure out if i need ( or how to use) a tuple to format the return from
: localtime(). i get a string now (wed jun 10 1999 xx:xx:xx) but i need
: to format it to yyyymmdd_hhmmss. Is there any switch ( %) or function
: that can be useful? Any help is appreciated.
"Here strftime comes to save the day!" (Okay, I won't do my bad
impressions of Andy Kaufman anymore.)
The time module has a handy function called strftime, which works like
format strings, but on the time tuple.
my_date = time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))
print my_date
19990610_145144
Or you can look at the less-standard, more versatile mxDateTime package
(http://starship.python.net/~lemburg/mxExtensions.html).
-Arcege
More information about the Python-list
mailing list