[Tutor] 12 hr to 24 hr time conversion

Raúl Cumplido raulcumplido at gmail.com
Wed Oct 26 11:21:31 CEST 2011

Hi Praveen,

Do you want to create the functon time24hr which with a string as an
argument of the type ("12:24am") or ("12:24pm") returns an output of
("0024hr") or ("1224hr"), right?

Is this format fixed? I mean, can you create a two arguments function? (i.e
time24hr("12:24", "AM") )

If you cannot change the format of the functions / arguments, I don't know
if there's any standard function to do that, but I will create a function
with this steps inside:
1.- Check the format of the input is ok (has the hour format and the am or
pm suffix)
2.- Check if it's am or pm
3.- Calculate if I had to modify the hour 12 -->  00 , 11 --> 23 ....
3.- Return the output format.


On Wed, Oct 26, 2011 at 10:46 AM, Praveen Singh <c2praveen30jun at gmail.com>wrote:

> How can i convert this-
> >>>time24hr('12:34am')
>  '0034hr'
> i searched in date module but i am not able to figure out what how to do
> this...
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Raúl Cumplido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111026/f887b015/attachment-0001.html>

More information about the Tutor mailing list