Skip to content

Instantly share code, notes, and snippets.

@jorovipe97
Last active August 14, 2017 18:52
Show Gist options
  • Save jorovipe97/f777f0a340e7f8dc1ae83e944682a852 to your computer and use it in GitHub Desktop.
Save jorovipe97/f777f0a340e7f8dc1ae83e944682a852 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
*
* @author B15S02est
*/
public class JavaApplication1 {
static String timeConversion(String s) {
// Complete this function
int arrlength = 4;
String res;
String isPm;
int hour;
String hourstr;
String dataArr[] = new String[3];
dataArr = s.split(":");
hourstr = "";
isPm = dataArr[2].substring(2);
dataArr[2] = dataArr[2].substring(0, 2);
hour = Integer.parseInt(dataArr[0]);
if (isPm.equals("AM")) {
if (hour == 12)
hour = 0;
}
else if (isPm.equals("PM")) {
if (hour == 12)
hour = 12;
else
hour += 12;
}
hourstr = String.valueOf(hour);
if (hour < 10) {
hourstr = "0"+hour;
}
res = hourstr+":"+dataArr[1]+":"+dataArr[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