We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2196800 commit 83113e0Copy full SHA for 83113e0
1 file changed
src/hackerrank/TimeConversion.java
@@ -0,0 +1,23 @@
1
+package hackerrank;
2
+
3
+public class TimeConversion {
4
+ static String timeConversion(String s) {
5
6
+ int timeInt = Integer.parseInt(s.substring(0, 2));
7
+ String format = s.substring(s.length()-2);
8
+ if(timeInt == 12 && format.equals("AM")){
9
+ timeInt = 0;
10
+ }else if(timeInt != 12 &&format.equals("PM")){
11
+ timeInt += 12;
12
+ }
13
14
+ String timeString = String.valueOf(timeInt).length() == 1 ? "0"+timeInt : String.valueOf(timeInt);
15
+ return timeString + s.substring(2,s.length()-2);
16
17
18
+ public static void main(String[] args) {
19
+ System.out.println(timeConversion("07:05:45PM")+", ans: 19:05:45");
20
+ System.out.println(timeConversion("12:01:00PM")+", ans: 12:01:00");
21
+ System.out.println(timeConversion("12:01:00AM")+", ans: 00:01:00");
22
23
+}
0 commit comments