I know that there are tons of different tutorials on time conversion, but this one got me very confused. My task is to read UTC DATE from Oracle DB and convert it into BST time (in a more human readable format).
Facts:
- Field in the DB is of
DATE
type. - When i perform
SELECT
query it returns2011-07-12 15:26:07
result. - I'm located in Poland, hence in July the TimeZone here is
UTC+2
What's happening:
On the Java side I'm using "classical" JDBC connection to the DB.
When I perform Timestamp timestampDate = resultSet.getTimestamp(COLUMN_NAME)
I get the result ... but ...
System.out.println(timestampDate)
prints to the console 2011-07-12 15:26:07.0
(which is similar to what I see in the DB tool.
System.out.println(timestampDate.getTime());
prints to the console 1310477167000
(which is wondering, because according to the ms to date
converter i found online, it's basically 2011-07-12 13:26:07.0
(2h earlier - which somehow might be related to Polish timezone on that date)
When I perform conversion according to this code:
ukDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ukDateFormatter.setTimeZone(TimeZone.getTimeZone("BST"));
return ukDateFormatter.format(timestampDate.getTime());
I get 2011-07-12 19:26:07
which I can't really explain.
I was also trying this
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(timestampDate);
calendar.setTimeZone(TimeZone.getTimeZone("BST"));
return ukDateFormatter.format(calendar.getTime());
with the same result.
Question
How to properly read DATE from Oracle DB in "timezone agnostic" format and convert it into BST?