The toString()
of Date
uses the format dow mon dd hh:mm:ss zzz yyyy
to return as a String
the value of the date, where:
dow
is the day of the week, in your case Sat
(saturday)
mon
is the month, the Feb
(February) of its result
dd
is the day of the month represented as two digits, of 01 to 31, in your case day 26
hh
is the time of day, with values of 00 until 23, the 11 of your leaving.
mm
is the representation, also in two digits, of the minute, the 38 of your leaving
ss
is the second, again represented in two digits, of 00 until 61
zzz
is the time zone, the BRT
may be empty if not available
yyyy
is the year, in four digits, as the 2015
So for the output you need, just use a DateFormat
in the pattern you need, in case, dd-MM-yyyy
. In this pattern, we will have:
dd
the day of the month, ranging from 01 to 31
MM
the month, no longer represented as Jan
, Feb
, etc., but in two digits, of 01 to 12
yyyy
being the year, in four digits
An example using Calendar
would be this:
final DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
final Calendar cal = Calendar.getInstance();
System.out.println(df.format(cal.getTime()));
This will print in the pattern you need.
Another point that is perhaps important to note: since getDate(String)
returns a java.sql.Date
and she is the subclass of java.util.Date
, it is not necessary to configure it in a Calendar, you can do directly, thus:
final DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
final Date date = rs.getDate("dataInicio");
System.out.println(df.format(date));
To display correctly on your dialog, you can use something this way:
final DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
final String dataFormatada = df.format(contato.getDataInicio().getTime());
JOptionPane.showMessageDialog(null, "Data de inicio: " + dataFormatada);
Thank you very much ;)
– Marcelo T. Cortes