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 220 views
2 answers 212 views
1 answer 114 views
114 views asked Jun 22, 2022 by avibootz
1 answer 140 views
140 views asked Jun 12, 2020 by avibootz
1 answer 156 views
1 answer 194 views
1 answer 182 views
...