I have saved a time as presentTime=datetime.datetime.utcnow()
It 's output is 2014-08-18 21:11:35.537000. How can this be formatted to : August 18 2014 - 21:11:35 instead?
datetime.utcnow
returns a datetime
object. You can use its strftime
method to convert it into a string of your desired format:
>>> datetime.datetime.utcnow().strftime('%B %d %Y - %H:%M:%S')
'August 20 2014 - 13:55:49'
the object you're getting is a datetime
instance. Just format it via its method strftime()
:
https://docs.python.org/2.7/library/datetime.html?highlight=date#datetime.datetime.strftime
update (thx @Ffisegyedd):
possible placeholders values: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With