You are viewing a single comment's thread. Return to all comments →
Java (without using LocalTime or any pre built formatter:
String solution = ""; String meridian = s.substring(s.length()-2, s.length()); String pureTime = s.substring(0, s.length()-2); String hours = s.substring(0, 2); if(meridian.equals("AM") && !hours.equals("12") || (meridian.equals("PM") && hours.equals("12"))) { solution = pureTime; } else if (meridian.equals("AM")) { solution = "00" + pureTime.substring(2,pureTime.length()); } else { int new_hours = Integer.parseInt(hours) + 12; solution = new_hours + pureTime.substring(2,pureTime.length()); } return solution;
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 →
Java (without using LocalTime or any pre built formatter: