We can convert Date to String in java using format() method of java.text.DateFormat class.
format() method of DateFormat
The format() method of DateFormat class is used to convert Date into String. DateFormat is an abstract class. The child class of DateFormat is SimpleDateFormat. It is the implementation of DateFormat class. The signature of format() method is given below:
Java Date to String Example
Let's see the simple code to convert Date to String in java.
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = dateFormat.format(date);
Example:
Output:
Let's see the full example to convert date and time into String in java using format() method of java.text.SimpleDateFormat class.
Output: