Date and Time

How to convert date to string java

public abstract class DateFormat extends Format

DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization

To format a date for the current Locale, use one of the static factory methods:

 myString = DateFormat.getDateInstance().format(myDate);

package com.candidjava.datetime;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateToString {
	public static void main(String[] args) {
		Date date=Calendar.getInstance().getTime();
		DateFormat dateFormat=new SimpleDateFormat("dd-MM-yyyy");
		String stringDate=dateFormat.format(date);
		System.out.println(stringDate);
	}

}

OUTPUT

18-11-2020