TIMEX TIMEX - 1 year ago 129
Python Question

How do I get a string format of the current date time, in python?

For example, on July 5, 2010, I would like to calculate the string

July 5, 2010

How should this be done?

Answer Source

You can use the datetime module for working with dates and times in Python. The strftime method allows you to produce string representation of dates and times with a format you specify.

>>> import datetime
>>> datetime.date.today().strftime("%B %d, %Y")
'July 23, 2010'
>>> datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
'10:36AM on July 23, 2010'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download