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
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
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
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