Epic Guy
Epic Guy

Reputation: 15

how to get hours and minutes using time.localtime in python

I have the folling line of code which returns the hour, but how do i get hours and minutes, preferable in this format 7:45.

print(time.localtime().tm_hour)

been racking my brain for hours trying to solve this but i am only new to python lol.

Thank you in advance for your help.

Upvotes: 1

Views: 1141

Answers (1)

DYZ
DYZ

Reputation: 57075

Function strftime() displays the local time by default:

time.strftime('%H:%M')
#'03:34'

Upvotes: 1

Related Questions