Read Time:2 Minute, 2 Second
Given a time in 12-hour AM/PM format, convert it to military (24-hour) time.
Note: – 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock.
– 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock.
Example
- Return ’12:01:00′.
- Return ’00:01:00′.
Function Description
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.
timeConversion has the following parameter(s):
- string s: a time in hour format
Returns
- string: the time in hour format
Input Format
A single string that represents a time in 12-hour clock format
Constraints
- All input times are valid
Sample Input
07:05:45PM
Sample Output
19:05:45
Java solution
2021
package Timeprj;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'timeConversion' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
public static String timeConversion(String s) {
char[] newtime= new char[10];
String st2= new String();
String st3= new String();
int size=s.length();
for(int i=0;i<size-2;i++) {
newtime[i]=s.charAt(i);
st3+=s.charAt(i);
}
if(s.charAt(8)=='P') {
int charPos1=Integer.parseInt(String.valueOf(newtime[0]));
int charPos2=Integer.parseInt(String.valueOf(newtime[1]));
if(charPos1==0) {
charPos2 +=12;
st2=charPos2+st3.substring(2, 8);
}
if(charPos1==1 & charPos2!=2) {
charPos2=Integer.parseInt(st3.substring(0, 2));
charPos2 +=12;
st2=charPos2+st3.substring(2, 8);
}
if( (charPos1==1) & (charPos2==2) ) {
st2 =st3;
}
}
else {
int charPos1=Integer.parseInt(String.valueOf(newtime[0]));
int charPos2=Integer.parseInt(String.valueOf(newtime[1]));
if(charPos1==0) {
st2 =st3;
}
if( (charPos1==1) & (charPos2==2) ) {
st2="00"+st3.substring(2, 8);
}
}
return st2;
}
}
public class Solution {
public static void main(String[] args) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
String s = bufferedReader.readLine();
String result = Result.timeConversion(s);
bufferedWriter.write(result);
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
jasa backlink pbn
A great post without any doubt.
free backlinks
Nice i really enjoyed reading your blogs. Keep on posting. Thanks
A great post without any doubt.
At this time, it seems like WordPress is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog? Great post, however, I was wondering if you could write a little more on this subject?
Wow, wonderful blog format! How long have you ever been running a blog
for? you made blogging glance easy. The overall glance of your site is magnificent, let alone the content material!
You can see similar: https://intellara.top
and here Intellara.top
I got this web site from my pal who shared with me regarding this site and at the
moment this time I am visiting this web site and reading very informative content here.
I saw similar here: sklep internetowy and also
here: e-commerce
Can you tell us more about this? I’d love to find out more details.