Skip to content
Related Articles

Related Articles

ChronoLocalDate toString() method in Java with Examples
  • Last Updated : 29 Apr, 2019

The toString() method of a ChronoLocalDate interface is used to get this date as a String, such as 2019-01-01.The output will be in the ISO-8601 format uuuu-MM-dd.

Syntax:

public String toString()

Parameters: This method does not accepts any parameters.

Return value: This method returns String which is the representation of this date, not null.

Below programs illustrate the toString() method:



Program 1:




// Java program to demonstrate
// ChronoLocalDate.toString() method
  
import java.time.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ChronoLocalDate object
        ChronoLocalDate localD
            = LocalDate.parse("2018-12-06");
  
        // print ChronoLocalDate
        System.out.println("ChronoLocalDate: "
                           + localD.toString());
    }
}
Output:
ChronoLocalDate: 2018-12-06

Program 2:




// Java program to demonstrate
// ChronoLocalDate.toString() method
  
import java.time.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ChronoLocalDate object
        ChronoLocalDate localD
            = LocalDate.parse("2021-06-30");
  
        // print ChronoLocalDate
        System.out.println("ChronoLocalDate: "
                           + localD.toString());
    }
}
Output:
ChronoLocalDate: 2021-06-30

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#toString–

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :