How to convert Date to String in Java Last Updated : 07 May, 2023 Comments Improve Suggest changes Like Article Like Report Given a date, the task is to write a Java program to convert the given date into a string. Examples: Input: date = "2020-07-27" Output: 2020-07-27 Input: date = "2018-02-17" Output: 2018-02-17 Method 1: Using DateFormat.format() method Approach: Get the date to be converted.Create an instance of SimpleDateFormat class to format the string representation of the date object.Get the date using the Calendar object.Convert the given date into a string using format() method.Print the result. Below is the implementation of the above approach: Java // Java program to convert Date to String import java.util.Calendar; import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; class GFG { // Function to convert date to string public static String convertDateToString(String date) { // Converts the string // format to date object DateFormat df = new SimpleDateFormat(date); // Get the date using calendar object Date today = Calendar.getInstance() .getTime(); // Convert the date into a // string using format() method String dateToString = df.format(today); // Return the result return (dateToString); } // Driver Code public static void main(String args[]) { // Given Date String date = "07-27-2020"; // Convert and print the result System.out.print( convertDateToString(date)); } } Output:07-27-2020Method 2: Using LocalDate.toString() method Approach: Get an instance of LocalDate from date.Convert the given date into a string using the toString() method of LocalDate class.Print the result. Below is the implementation of the above approach: Java // Java program to convert Date to String import java.time.LocalDate; class GFG { // Function to convert date to string public static String convertDateToString(String date) { // Get an instance of LocalTime // from date LocalDate givenDate = LocalDate.parse(date); // Convert the given date into a // string using toString()method String dateToString = givenDate.toString(); // Return the result return (dateToString); } // Driver Code public static void main(String args[]) { // Given Date String date = "2020-07-27"; // Convert and print the result System.out.print( convertDateToString(date)); } } Output:2020-07-27Method 3: Using DateTimeFormatter.format() methodApproach:Get an instance of LocalDate from date.Create a DateTimeFormatter object to format the LocalDate object as a string.Use the format() method of the DateTimeFormatter object to convert the LocalDate object to a string.Print the result. Below is the implementation of the above approach: Java // Java program to convert Date to String import java.time.LocalDate; import java.time.format.DateTimeFormatter; class GFG { // Function to convert date to string public static String convertDateToString(String date) { // Get an instance of LocalTime // from date LocalDate givenDate = LocalDate.parse(date); // Create a DateTimeFormatter object to format LocalDate DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // Use the format() method to convert LocalDate to string String dateToString = givenDate.format(formatter); // Return the result return (dateToString); } // Driver Code public static void main(String args[]) { // Given Date String date = "2022-12-31"; // Convert and print the result System.out.print( convertDateToString(date)); } } Output2022-12-31 Comment More infoAdvertise with us Next Article How to convert Date to String in Java P prashant_srivastava Follow Improve Article Tags : Strings Java Programs DSA Java-Date-Time Java-LocalDate Java-String-Programs +2 More Practice Tags : Strings Similar Reads How to Convert Java Date to XML DateTime String? In order to define a date and time, the DateTime data type is used. DateTime is defined in the format as âYYYY-MM-DDThh:mm:ssâ where: YYYY states the yearMM represents the monthDD shows the dayT indicates the beginning of the time segment needed.Hh determines the hourmm represents the minutess indic 4 min read Java Program to Convert Date to String The date type object can be converted to a string in Java using a large variety of in-built classes available in Java. Given a date, we need to convert the date to a given format of the string. Examples: Input: date = â2020-11-13âOutput: 2020-11-13 Input: date = â2020-12-14âOutput: 2020-12-14 Method 3 min read How to Convert a String to a LocalDate in Java? Converting a String to a LocalDate in Java is a common operation when you are dealing with date inputs from users. Java provides the LocalDate class in the java.time package for representing a date without time information. LocalDate class is part of the java.time package introduced in Java 8. Strin 2 min read How to Convert a String to a Timestamp in Java? In this article, we will learn how to convert a String to a timestamp in Java, for this java provides a built-in package that is java.sql.Timestamp. By using this package, we can be able to convert the String value into the required timestamp format. But one thing we need to remember that is we need 2 min read How to Convert ISO 8601 Compliant String to java.util.Date? The ISO 8601 standard provides a convenient way to represent dates and times in a string format that can be easily parsed. In this article, we will learn how to convert a string in ISO 8601 format to a java.util.Date object. Conversion of ISO 8601 String to a DateTo convert this ISO 8601 string to a 2 min read Like