How to get hour and minutes from datetime in Python

2 Answers

0 votes
from datetime import datetime

dt = datetime.strptime("21/04/2021 12:54:34", "%d/%m/%Y %H:%M:%S")

print("{:d}:{:02d}".format(dt.hour, dt.minute))





 
'''
run:
  
12:54
   
'''

 



answered Apr 21, 2021 by avibootz
0 votes
from datetime import datetime

dt = datetime.strptime("21/04/2021 12:54:34", "%d/%m/%Y %H:%M:%S")

print(dt.hour, ":", dt.minute)





 
'''
run:
  
12 : 54
   
'''

 



answered Apr 21, 2021 by avibootz

Related questions

1 answer 307 views
2 answers 339 views
1 answer 199 views
199 views asked Jun 22, 2022 by avibootz
1 answer 215 views
215 views asked Jun 12, 2020 by avibootz
1 answer 226 views
1 answer 302 views
1 answer 274 views
...