Skip to content

Instantly share code, notes, and snippets.

@jorovipe97
Created August 10, 2017 18:19
Show Gist options
  • Save jorovipe97/a696ffe990538df5d2fd8c6c3eb0bfde to your computer and use it in GitHub Desktop.
Save jorovipe97/a696ffe990538df5d2fd8c6c3eb0bfde to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static String timeConversion(String s) {
// Complete this function
int arrlength = 4;
int dateArrLength = 3;
String res;
int dateArr[] = new int[3];
String dataArr[] = new String[4];
dataArr = s.split(":");
for (int i = 0; i < dateArrLength-1; i++) {
dateArr[i] = Integer.parseInt(dataArr[i]);
}
dateArr[2] = Integer.parseInt(dataArr[2].substring(0, 2));
if (dataArr[2].substring(2, 4).equals("PM")) {
if (dateArr[0] == 12)
dateArr[0] = 0;
else
dateArr[0] += 12;
}
res = dateArr[0]+":"+dateArr[1]+":"+dateArr[2];
return res;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
String result = timeConversion(s);
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment