goldb.org home

AS OF MAY 2008, THIS BLOG IS NO LONGER BEING UPDATED.
Visit the new blog at: http://coreygoldberg.blogspot.com



 Tuesday, January 09, 2007

Python - Formatted Dates and Times

I am not sure why, but every time I need to use some formatted dates or times in Python, I end up spending about 20 minutes going through the docs and reading up on the datetime module; which leads to more confusion.

So for my own clarity, here is how we do it using only the time module:

>>> import time
>>> print time.strftime("%m/%d/%y %H:%M:%S", time.localtime())
01/09/07 12:17:25

All of the formatting options for strftime() can be found here: http://docs.python.org/lib/module-time.html

#    Comments [0] |
Comments are closed.