[Tutor] 12 hr to 24 hr time conversion

Peter Otten __peter__ at web.de
Wed Oct 26 11:23:10 CEST 2011

Praveen Singh wrote:

> How can i convert this-
>  '0034hr'
> i searched in date module but i am not able to figure out what how to do
> this...

>>> time.strftime("%H:%M", time.strptime("12:34am", "%I:%M%p"))

>>> datetime.datetime.strptime("12:34am", "%I:%M%p").strftime("%H:%M")

>>> datetime.datetime.strptime("12:34am", "%I:%M%p").strftime("%H:%Mhr")

The supported formats are explained here:


More information about the Tutor mailing list