Object such as java.sql.Date
and java.util.Date
(of which java.sql.Date
is a subclass) don’t have a format of themselves. You use a java.text.DateFormat
object to display these objects in a specific format, and it’s the DateFormat
(not the Date
itself) that determines the format.
For example:
Date date = ...; // wherever you get this
DateFormat df = new SimpleDateFormat("dd MMMM yyyy");
String text = df.format(date);
System.out.println(text);
Note: When you print a Date
object without using a DateFormat
object, like this:
Date date = ...;
System.out.println(date);
then it will be formatted using some default format. That default format is however not a property of the Date
object that you can change.