Time Conversion

  • + 0 comments
     public static String timeConversion(String s) {
        int shift = s.endsWith("PM") ? 12 : 0;
        int hours = Integer.parseInt(s.substring(0, 2));
        hours = (hours == 12) ? shift : hours + shift;
        return String.format("%02d%s", hours, s.substring(2, 8));
    }