-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeconversion.java
More file actions
39 lines (32 loc) · 856 Bytes
/
Copy pathTimeconversion.java
File metadata and controls
39 lines (32 loc) · 856 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
33
34
35
36
37
38
// Java program to convert time from AM-PM or PM-AM
// 12:00:30AM
// Write time in the above format.
import java.util.Scanner;
public class Timeconversion {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Input Time");
String time = input.nextLine();
String ampm = time.substring(8);
int hr = Integer.parseInt(time.substring(0, 2));
int hh1 = hr,hh2=0;
if(ampm.equals("AM")){
if(hr==12){
System.out.println("00"+time.substring(2,8));
}
else{
System.out.println("Time is:" +time);
}
}
else
{
if(hh1<12){
hh2=12+hh1;
System.out.println(Integer.toString(hh2)+time.substring(2,8));
}
else
System.out.println(time.substring(0,8));
}
}
}