I saved the time as presentTime=datetime.datetime.utcnow()
presentTime=datetime.datetime.utcnow()
Exit: 2014-08-18 21:11: 35.537000. How can this be formatted before: August 18, 2014 - 21:11:35 instead?
datetime.utcnow returns a datetime object, you can use the strftime method to convert it to a string of the required format:
datetime.utcnow
datetime
strftime
>>> datetime.datetime.utcnow().strftime('%B %d %Y - %H:%M:%S') 'August 20 2014 - 13:55:49'
the object you receive is an instance of datetime . Just format it using strftime() method: https://docs.python.org/2.7/library/datetime.html?highlight=date#datetime.datetime.strftime
strftime()
update (thanks @Ffisegyedd):
possible placeholders values: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
import datetime presentTime=datetime.datetime.utcnow() print presentTime.strftime('%B %d %Y - %H:%M:%S')
Source: https://habr.com/ru/post/1200756/More articles:The semantic correctness of non-specific functions of the C ++ template - c ++Unpacking nested C structures in Python - pythonHow to update columns in a unique request of my query on Sql Server? - c #What is the life cycle of unit tests in C # - c #Launching Tomcat7 war against Grails run-app - grailsHow to get the full path to the selected node in jstree? (Root node to selected node) - jqueryIs TextToSpeech supported in Google Glass? - google-glassHow to create markdown document for each row of data in R - riOS 8 - Creating Temporary NSManagedObjects - iosSetting private static final field with reflection - javaAll Articles