Java Date To String Example
Chapter:
String Handling
Last Updated:
15-07-2016 10:35:03 UTC
Program:
/* ............... START ............... */
public class JavaDateToString {
public static void main(String args[]) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = dateFormat.format(date);
System.out.println("Date converted to String: " + strDate);
}
}
/* ............... END ............... */
Output
Date converted to String: 2016-55-19 02:55:48
Notes:
-
This Java Date to String example shows how to convert java.util.Date to String in Java.
- First step in date to string conversion is to create a date format using SimpleDateFormat class.
- Call format() method of SimpleDateFormat by passing Date object this will return String representation of date into specified date format.
Tags
Java Date to String, Java