Time Conversion

  • + 0 comments

    My solution in Java:

    public static String timeConversion(String s) {
        // Write your code here
            String[] time = s.split(":");
            int hour = Integer.valueOf(time[0]) + 12;
            if(time[2].contains("PM")){
                time[0] = String.valueOf(hour==24?hour-12:hour);
            } else {
                time[0] = time[0].contains("12")?"00":time[0];
            }
            return time[0]+":"+time[1]+":"+time[2].substring(0, 2);
        }