Time Conversion

  • + 0 comments

    my java solution: ` s= s.trim(); String timeMarker=s.substring(8); String originalTime = s.substring(0, 8); String[] originalTimeList= originalTime.split(":"); String hour = originalTimeList[0]; Integer hourInt = Integer.parseInt(hour); StringBuilder newTime = new StringBuilder();

    if(timeMarker.equals("PM")){
        if(hourInt!=12){
            hourInt+=12;
            hour= String.valueOf(hourInt);
        }
    }
    else{
        if(hourInt==12){
            hour= "00";
        }
    }
    
    return newTime.append(String.valueOf(hour)).append(":")
    .append(originalTimeList[1]).append(":")
    .append(originalTimeList[2]).toString();
    

    `