Time Conversion

  • + 0 comments

    Java:

    public static String timeConversion(String str) {

      String time12HourFormat = str;
    
        SimpleDateFormat inputFormat = new SimpleDateFormat("hh:mm:ssa");
    
        SimpleDateFormat outputFormat = new SimpleDateFormat("HH:mm:ss");
    
        try{
    
            Date date = inputFormat.parse(time12HourFormat);
    
            String time24HourFormat = outputFormat.format(date); 
    
            return time24HourFormat;
    
        } catch (ParseException e) {    
            e.printStackTrace();                    
        }
        return "";
       }