Printing just the time and no date from time.ctime()?

import time
print(time.ctime())

time = (time.ctime())

prints out

“Tue Mar 1 12:43:53 2016”

Is there anyway to print JUST the “12:43:53” section of this statement?

EDIT: Solved


from time import strftimestrftime("%m/%d/%Y %H:%M")


print(strftime("%H:%M:%S"))

Used this instead.

Afaik ctime() doesn’t offer any formatting options. You could use localtime() instead. It returns a struct which then can be formatted with strftime():


t = time.localtime()
print(time.strftime('%H:%M:%S', t))

https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime

import datetime
now= datetime.datetime.now
datetime.time(now.hour, now.minute, now.second
datetime.time(11,23, 44 )

happy bl