Taking and approach using Java java.util.Calendar, java.util.Date and java.time.format.DateTimeFormatter.
public static String timeConversion(String s) {
// Write your code here
String result = "";
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ssa");
try {
Date date = formatter.parse(s);
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(date); // assigns calendar to given date
result= String.format("%02d:%02d:%02d", calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),calendar.get(Calendar.SECOND));
return result;
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
Sem comentários:
Enviar um comentário