Time Formatting

0

I'm doing an application that divided a String to write the same in the time format. But if I put 102330 instead of returning me 10:23:30 it brings me 1:02:33 being that if I put 112126 it formats correctly for 11:21:26. If anyone can help me, thank you.

StringBuilder format = new StringBuilder();
                                    format.append(hora.substring(0, 2)).
                                            append(":").append(hora.substring(2, 4)).
                                            append(":").append(hora.substring(4, 6));
                                    System.out.println("Hora: " +format);
    
asked by anonymous 05.07.2016 / 20:12

1 answer

2

The code is correct, there is probably a space at the beginning of text 102330.

Try to debug the function or make a simple sysout with the original value to see the space.

    
05.07.2016 / 21:52