+ 1

How to convert a given 12 hour time format in hh:mm:ss AM/PM to 24 hour format if the function only takes a string as an input

lets say time given is 7:49:50 PM the output should be 19:49:50 the problem I am facing is that how to read from string and compute the string values from string to numeric then return a 24 hour format that is also a string.

16th Mar 2018, 6:34 PM
Dibya Prakash Paul
Dibya Prakash Paul - avatar
7 Answers
+ 3
Use an If statement to see if the string includes pm or am and add 12 to the first number before the ā€œ:ā€ if itā€™s pm
16th Mar 2018, 7:51 PM
Ariela
Ariela - avatar
+ 1
in Java there is a class to deal with time and date...... check this link out..... https://beginnersbook.com/2014/
16th Mar 2018, 7:51 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
Thanks everyone, finally got a working code! https://code.sololearn.com/cO9CVRNBHiX9/?ref=app
17th Mar 2018, 2:54 PM
Dibya Prakash Paul
Dibya Prakash Paul - avatar
0
@Ariela .. yup that's a good one šŸ‘
16th Mar 2018, 7:57 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
Try running on a pc, i am getting the results though!
18th Mar 2018, 4:09 AM
Dibya Prakash Paul
Dibya Prakash Paul - avatar