Python Datetime – How to Get the Current Time in Python? datetimepythontime How do I get the current time in Python? Best Answer Use datetime: >>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2009, 1, 6, 15, 8, 24, 78915) >>> print(now) 2009-01-06 15:08:24.789150 For just the clock time without the date: >>> now.time() datetime.time(15, 8, 24, 78915) >>> print(now.time()) 15:08:24.789150 To save typing, you can import the datetime object from the datetime module: >>> from datetime import datetime Then remove the prefix datetime. from all of the above. Related SolutionsPython – How to Get Current Time in Milliseconds Using time.time(): import time def current_milli_time(): return round(time.time() * 1000) Then: >>> current_milli_time() 1378761833768 Related Question
Best Answer
Use
datetime
:For just the clock time without the date:
To save typing, you can import the
datetime
object from thedatetime
module:Then remove the prefix
datetime.
from all of the above.