-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime_Conversion.java
More file actions
32 lines (25 loc) · 937 Bytes
/
Time_Conversion.java
File metadata and controls
32 lines (25 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Challenge link : https://www.hackerrank.com/challenges/time-conversion/problem?isFullScreen=true&h_r=next-challenge&h_v=zen
// Git Hub REPO Link : https://github.com/piyushpatelcodes/100-Days-Java-Hackerrank
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Time_Conversion{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
DateFormat inFormat = new SimpleDateFormat( "hh:mm:ssaa");
DateFormat outFormat = new SimpleDateFormat( "HH:mm:ss");
Date date = null;
try {
date = inFormat.parse(s);
}catch (ParseException e ){
e.printStackTrace();
}
if( date != null ){
String myDate = outFormat.format(date);
System.out.println(myDate);
}
}
}