Date formats

Skip Montanaro skip at mojam.com
Fri Jun 11 21:47:36 CEST 1999


mike milliger 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(). 

Mike,

You want to use time.strftime if it's available on your platform. 
Here's a simple example:

  >>> import time
  >>> now = time.localtime(time.time())
  >>> now
  (1999, 6, 11, 15, 48, 40, 4, 162, 1)
  >>> time.strftime("%m/%d/%y", now)
  '06/11/99'
  >>> time.strftime("%Y-%m-%d", now)
  '1999-06-11'

-- 
Skip Montanaro	| Mojam: "Uniting the World of Music"
http://www.mojam.com/
skip at mojam.com  | Musi-Cal: http://www.musi-cal.com/
518-372-5583




More information about the Python-list mailing list