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

Viewed 192481

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

 July 5, 2010

How should this be done?

5 Answers

If you don't care about formatting and you just need some quick date, you can use this:

import time
print(time.ctime())

With time module:

import time
time.strftime("%B %d, %Y")
>>> 'July 23, 2010'
time.strftime("%I:%M%p on %B %d, %Y")
>>> '10:36AM on July 23, 2010'

For more formats: www.tutorialspoint.com

Related