Skip to content
Advertisement

how do i get only the time in python without the date and year?

I need to get time in python and i am using time.ctime() and it returns this Thu Jul 8 15:37:26 2021

But i only need 15:37:26 and i cant figure out how to get only this and not the date and year.

I already tried using datetime where i could not figure it out either so im trying with time now.

here is a bit of code for the context:

cas = time.ctime()
cas = str(cas)
api.update_status('nyni je:'+ cas )
time.sleep(60)

Anyone know how to do it?

Advertisement

Answer

   import datetime
   print(datetime.datetime.now().strftime("%H:%M:%S"))
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement