Skip to content

Instantly share code, notes, and snippets.

@setanjan123
Created November 29, 2017 14:02
Show Gist options
  • Save setanjan123/85c32c056f753cd4ef428646644c7709 to your computer and use it in GitHub Desktop.
Save setanjan123/85c32c056f753cd4ef428646644c7709 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) {
String time[]=s.split(":");
if(time[2].contains("PM"))
{ if(Integer.parseInt(time[0])!=12)
{ int hours=Integer.parseInt(time[0])+12;
time[0]=Integer.toString(hours);
}
}
else if(time[2].contains("AM"))
{
if(Integer.parseInt(time[0])==12)
time[0]="00";
}
String str = String.join(":", time);
String str2=str.substring(0,8);
return str2;
}
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