Generate current time in Python


Import modules

import datetime

Grab current datetime

datetime.datetime.now()
datetime.datetime(2017, 9, 7, 15, 6, 49, 819248)

Grab current time

datetime.datetime.now().time()
datetime.time(15, 8, 51, 723898)

Grab datetime in more readable format

str(datetime.datetime.now())
'2017-09-07 15:06:50.211892'


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.