Duda print String with Java time format

0

I have a program that receives a time in this format from a GPS: HHmmss.ss and I save it in a String, I wanted to know some way to print the String with this format: HH: mm: ss. I just need to print the time on the screen

    
asked by Mins 26.09.2018 в 13:10
source

3 answers

0
DateFormat formatoOrigen = new SimpleDateFormat("HHmmss.00");
DateFormat formatoDestino = new SimpleDateFormat("HH:mm:ss");
Date fecha = formatoOrigen.parse("090230.00");
String fechaFormato = formatoDestino.format(fecha);
System.out.println(fechaFormato);

    
answered by 26.09.2018 / 20:20
source
0

Since the positions of the time are always fixed, you can do the following:

String output = null;
String input = "121516.00";

output = input.substring(0, 2) + ":";
output += input.substring(2, 4) + ":";
output += input.substring(4, 6);

System.out.print(output); //Output -> 12:15:16
    
answered by 26.09.2018 в 15:58
-1

Hello friend you can get the system time with the following code, try to have it work for you.

 public String hora(){
        return new SimpleDateFormat("HH:mm:ss a", Locale.US).format(new Date());
    }

Restoring the system time don a is Am or Pm , I hope it helps you

    
answered by 26.09.2018 в 15:20