Reputation: 58030
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");
Upvotes: 3
Views: 4364
Reputation: 7899
java.sql.Timestamp
objects 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());
Upvotes: 0
Reputation: 8154
I think this might work:
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp.getTime());
I believe they are both based on epoch.
Upvotes: 1
Reputation: 135992
java.sql.Timestamp just like java.util.Date which it extends holds time since since January 1, 1970, 00:00:00 GMT with the only difference that it also holds nanos (see API). It does not depend on time zone and you cannot convert it to local time zone.
Upvotes: 1