You are viewing a single comment's thread. Return to all comments →
I used Java and tried to keep it simple and easy to read
public static String timeConversion(String s) { int hoursIn24 = 0; int hoursIn12 = 0; String result = s; hoursIn12 = Integer.parseInt(s.substring(0, 2)); if (s.indexOf("AM") > 0){ if (hoursIn12 == 12){ result = "00" + s.substring(2, s.length() - 2); } else{ result = s.substring(0, s.length() - 2); } } else{ if (hoursIn12 == 12){ result = s.substring(0, s.length() - 2); } else{ hoursIn24 = 12 + hoursIn12; result = hoursIn24 + s.substring(2, s.length() - 2); } } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
I used Java and tried to keep it simple and easy to read