“java.text.SimpleDateFormat” can be used to convert a java date object (java.util.Date) to a string (String, StringBuffer, StringBuilder, etc..).
The whole magic is done by SimpleDateFormat, the child of “java.text.DateFormat”, which, as its name suggests, formats the date by a provided template.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ConvertDateToString
{
public static void main(String[] args)
{
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
System.out.println("Date String: " + date);
}
}