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.
public class TimeConversion {
public static void main(String[] args) {
String s="07:05:45PM";
System.out.println(timeConversion(s));
}
static String timeConversion(String s) {
/*
* Write your code here.
*/
String str="";
if(!s.substring(0,2).equals("12")&&s.contains("PM")){
str= Integer.toString(Integer.parseInt(s.substring(0,2))+12);
s =str+s.substring(2,s.length());
}
if(s.substring(0,2).equals("12")&&s.contains("AM")){
str="00";
s =str+s.substring(2,s.length());
}
Test cases are falingin for this solution , can anyone provide me the solution an
return s.substring(0,s.length()-2);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
public class TimeConversion { public static void main(String[] args) { String s="07:05:45PM"; System.out.println(timeConversion(s)); }
}