I am retrieving results from a timestamp mysql database column. I need to convert these results to my local timezone.Timestamp timestamp = rs.getTimestamp("mytimestamp");
-
refer this stackoverflow.com/questions/14070572/…Peeyush– Peeyush2013-05-31 02:09:08 +00:00Commented May 31, 2013 at 2:09
Add a comment
|
3 Answers
java.sql.Timestampobjects don't have time zones - they are just like java.util.Date.
However you can display time in your TimeZone like
Calendar localTime = Calendar.getInstance(TimeZone.getDefault());
localTime .setTimeInMillis(timeStamp.getTime());
2 Comments
Jonathan
Unfortunately Timestamp does have zones (inherited from java.util.Date) depending on which constructor is used. Some JDBC drivers still use the deprecated constructor in which case the local timezone is selected. See docjar.com/html/api/java/util/Date.java.html (line 252)
BPS
@Jonathan , neither Date nor Timestamp has time zones though they are related to UTC in a way. Any hint in the javadoc that they have time zones was deprecated in Java 1.1 back in early 1997. Your comment refers to such a deprecated method. Notice that there is no getTimeZone method in Date as there is in Calendar.