H
Hole
Hi there,
I've noticed some strange problems in my app...after few hours of
debugging I found out that problems are in java.sql.Timestamp...
Please, if you have spare time, could you look at the following code
and test it with some dates?:
public static Timestamp toSqlTimestamp(String date, String fmt) throws
ParseException, Exception {
Timestamp res = null;
try {
SimpleDateFormat f = new SimpleDateFormat(fmt);
res = new Timestamp(f.parse(date).getTime());
} catch(ParseException pexc) {
throw pexc;
} catch(Exception exc) {
throw exc;
}
return res;
}
This code strangely returns wrong hours, but only whit particular
dates. For example, time from 2009-03-29 02:00:00 to 2009-03-29
03:00:00 (this excluded) returns a timestamp of one hour more...
This is the output of a test program I made:
Original: 2009-03-29 01:45:00
toSqlTimestamp: 2009-03-29 01:45:00
Original: 2009-03-29 02:00:00
toSqlTimestamp: 2009-03-29 03:00:00
Original: 2009-03-29 02:15:00
toSqlTimestamp: 2009-03-29 03:15:00
Original: 2009-03-29 02:30:00
toSqlTimestamp: 2009-03-29 03:30:00
Original: 2009-03-29 02:45:00
toSqlTimestamp: 2009-03-29 03:45:00
Original: 2009-03-29 03:00:00
toSqlTimestamp: 2009-03-29 03:00:00
I've noticed some strange problems in my app...after few hours of
debugging I found out that problems are in java.sql.Timestamp...
Please, if you have spare time, could you look at the following code
and test it with some dates?:
public static Timestamp toSqlTimestamp(String date, String fmt) throws
ParseException, Exception {
Timestamp res = null;
try {
SimpleDateFormat f = new SimpleDateFormat(fmt);
res = new Timestamp(f.parse(date).getTime());
} catch(ParseException pexc) {
throw pexc;
} catch(Exception exc) {
throw exc;
}
return res;
}
This code strangely returns wrong hours, but only whit particular
dates. For example, time from 2009-03-29 02:00:00 to 2009-03-29
03:00:00 (this excluded) returns a timestamp of one hour more...
This is the output of a test program I made:
Original: 2009-03-29 01:45:00
toSqlTimestamp: 2009-03-29 01:45:00
Original: 2009-03-29 02:00:00
toSqlTimestamp: 2009-03-29 03:00:00
Original: 2009-03-29 02:15:00
toSqlTimestamp: 2009-03-29 03:15:00
Original: 2009-03-29 02:30:00
toSqlTimestamp: 2009-03-29 03:30:00
Original: 2009-03-29 02:45:00
toSqlTimestamp: 2009-03-29 03:45:00
Original: 2009-03-29 03:00:00
toSqlTimestamp: 2009-03-29 03:00:00