I have a JDBC Date column, which if a i use getDate is get the \'date\' part only 02 Oct 2009 but if i use getTimestamp i get the full \'date\
You should be aware that java.util.Date
(and also java.sql.Date
and java.sql.Timestamp
, which are subclasses of java.util.Date
) don't know anything about timezones, or rather, they are always in UTC.
java.util.Date
and its subclasses are nothing more than a container for a "number of milliseconds since 01-01-1970, 12:00 AM UTC" value.
To display a date in a specific timezone, convert it to a string by using a java.text.DateFormat
object. Set the timezone on that object by calling the setTimeZone()
method. For example:
Date date = ...; // wherever you get this from
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Make the date format show the date in CET (central European time)
df.setTimeZone(TimeZone.getTimeZone("CET"));
String text = df.format(date);