You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not a bug. I assume the 28th 2:00 is the cutover time for DST in Russia (it is the 28th 2:00 in the Netherlands). In that case 2:15 does not exist and is essentially an invalid time. In that situation Java will by default treat it leniently and convert the time to the assumed correct time of 3:15.
The following code will print out: Sun Mar 28 03:15:00 CEST 2010 (as it should):
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("nl"));
df.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));
Date date = df.parse("28-03-10 2:15");
System.out.println(date);
You are quite right that '2010-03-28 02:15 is an invalid time in Moscow.
But what if we must treat database time as Greenwich Time?
I checked JDBC drivers for Oracle and MS SQL Server.
Both drivers give the same result:
dt1 dt2
...
getTimestamp("dt",gmtCalendar): 2010-03-28 06:15:00.0 2010-03-28 07:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269746100000
It looks like this bug was fixed in Jaybird 2.2:
dt1 dt2
getTimestamp("dt",gmtCalendar): 2010-03-28 04:15:00.0 2010-03-28 05:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269746100000
This is in CEST.
Result when using Jaybird 2.1.6:
dt1 dt2
getTimestamp("dt",gmtCalendar): 2010-03-28 04:15:00.0 2010-03-28 04:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269742500000
Submitted by: Stanislav Kroo (kroo)
Assigned to: Roman Rokytskyy (rrokytskyy)
There is no possibility to get correctly Timestamp values from the moment of transition to summertime during one hour.
For example, if JRE runned at GMT+3 TimeZone with active Daylight Saving Time option (Moscow), both values "2010-03-28 02:15" and "2010-03-28 03:15" selected as "2010-03-28 03:15:00.0".
-------- SQL script --------->
create table Test(dt1 Timestamp, dt2 Timestamp)
insert into Test values('2010-03-28 02:15:00.0', '2010-03-28 03:15:00.0')
-------- Java code --------->
java.sql.ResultSet rs = connection.createStatement().executeQuery("select * from Test");
rs.next();
System.out.println("\t\t\t\t\t\tdt1 \t\t\tdt2");
System.out.println("getString(\"dt\"): \t\t\t\t" + rs.getString("dt1") + "\t" + rs.getString("dt2"));
System.out.println("getTimestamp(\"dt\"): \t\t\t\t" + rs.getTimestamp("dt1") + "\t" + rs.getTimestamp("dt2"));
System.out.println("getTimestamp(\"dt\").getTime(): \t\t\t" + rs.getTimestamp("dt1").getTime() + "\t\t" + rs.getTimestamp("dt2").getTime());
Calendar gmtCalendar = Calendar.getInstance( java.util.TimeZone.getTimeZone("GMT-0:00") );
System.out.println("getTimestamp(\"dt\",gmtCalendar): \t\t" + rs.getTimestamp("dt1",gmtCalendar) + "\t" + rs.getTimestamp("dt2",gmtCalendar));
System.out.println("getTimestamp(\"dt\",gmtCalendar).getTime(): \t" + rs.getTimestamp("dt1",gmtCalendar).getTime() + "\t\t" + rs.getTimestamp("dt2",gmtCalendar).getTime());
-------- Result --------->
dt1 dt2
getString("dt"): 2010-03-28 03:15:00.0 2010-03-28 03:15:00.0
getTimestamp("dt"): 2010-03-28 03:15:00.0 2010-03-28 03:15:00.0
getTimestamp("dt").getTime(): 1269731700000 1269731700000
getTimestamp("dt",gmtCalendar): 2010-03-28 06:15:00.0 2010-03-28 06:15:00.0
getTimestamp("dt",gmtCalendar).getTime(): 1269742500000 1269742500000
The text was updated successfully, but these errors were encountered: