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 212 views
2 answers 204 views
1 answer 109 views
109 views asked Jun 22, 2022 by avibootz
1 answer 136 views
136 views asked Jun 12, 2020 by avibootz
1 answer 151 views
1 answer 184 views
1 answer 174 views
...