Java Date Time - LocalDateTime toString() example








LocalDateTime toString() Outputs this date-time as a String, such as 2014-12-03T10:15:30.

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

uuuu-MM-dd'T'HH:mm 
uuuu-MM-dd'T'HH:mm:ss 
uuuu-MM-dd'T'HH:mm:ss.SSS 
uuuu-MM-dd'T'HH:mm:ss.SSSSSS 
uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS 

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





Syntax

toString has the following syntax.

public String toString()

Example

The following example shows how to use toString.

import java.time.LocalDateTime;

public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.now();
    
    System.out.println(a.toString());
  }
}

The code above generates the following result.