We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringtimeConversion(Strings){// Write your code hereStringperiod=s.substring(s.length()-2);StringtimeWithoutPeriod=s.substring(0,s.length()-2);String[]timeParts=timeWithoutPeriod.split(":");inthour=Integer.parseInt(timeParts[0]);intminute=Integer.parseInt(timeParts[1]);intsecond=Integer.parseInt(timeParts[2]);if(period.equals("AM")&&hour==12){hour=0;}elseif(period.equals("PM")&&hour!=12){hour+=12;}// Format the time in 24-hour format (HH:mm:ss)returnString.format("%02d:%02d:%02d",hour,minute,second);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 5
You are viewing a single comment's thread. Return to all comments →
JAVA