-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTime Conversion.java
More file actions
35 lines (33 loc) · 839 Bytes
/
Time Conversion.java
File metadata and controls
35 lines (33 loc) · 839 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
//method-1
public static String timeConversion(String s) {
// Write your code herea
int h1=(int)s.charAt(0)-'0';
int h2=(int )s.charAt(1)-'0';
int h=(h1*10+h2);
String res="";
if(s.charAt(8)=='A')
{
if(h==12)
{
res+="00";
for(int i=2;i<s.length()-2;i++)
{
res+=s.charAt(i);
}
}else{
for(int i=0;i<s.length()-2;i++)
{
res+=s.charAt(i);
}
}
}else{
if(h<12)
h+=12;
res+=h;
for(int i=2;i<s.length()-2;i++)
{
res+=s.charAt(i);
}
}
return res;
}