Conversion from 12 hours time to 24 hours time in java

后端 未结 14 1099
失恋的感觉
失恋的感觉 2020-11-29 06:08

In my app, I have a requirement to format 12 hours time to 24 hours time. What is the method I have to use?

For example, time like 10

14条回答
  •  攒了一身酷
    2020-11-29 06:38

    This is the extract of code that I have done.

        String s="08:10:45";
        String[] s1=s.split(":");
        int milipmHrs=0;
        char[] arr=s1[2].toCharArray();
        boolean isFound=s1[2].contains("PM");
        if(isFound){
            int pmHrs=Integer.parseInt(s1[0]);
            milipmHrs=pmHrs+12;
            return(milipmHrs+":"+s1[1]+":"+arr[0]+arr[1]);
        }
        else{
    
            return(s1[0]+":"+s1[1]+":"+arr[0]+arr[1]);
        }
    

提交回复
热议问题