Java Date Time - LocalTime toString() example








LocalTime toString() outputs this time as a String, such as 10:15.

The output will be one of the following ISO-8601 formats:

HH:mm HH:mm:ss 
HH:mm:ss.SSS 
HH:mm:ss.SSSSSS 
HH:mm:ss.SSSSSSSSS

The format used will be the shortest that outputs the full value of the time where the omitted parts are zero.





Syntax

toString has the following syntax.

public String toString()

Example

The following example shows how to use toString.

import java.time.LocalTime;

public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();

    System.out.println(l.toString());
  }
}

The code above generates the following result.