Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.Date to joda time conversion

oracle sql:

select trunc( sysdate, 'Month') month
from dual

java:

java.sql.Date sqlDate = resultSet.getDate("month");
log.info(sqlDate);
DateTime dateTime = new DateTime(sqlDate.getTime());
log.info(dateTime);
dateTime = dateTime.withMillisOfDay(0);
log.info(dateTime);

output:

2012-01-01

2012-01-01T 01:00:00.000+07:00

2012-01-01T 00:00:00.000+07:00

where did the extra hour?

like image 600
turbanoff Avatar asked Jan 13 '12 04:01

turbanoff


1 Answers

Use LocalDate.fromDateFields(date) to interpret the SQL date as local (ignoring time-zone). You can then use methods on LocalDate to get a DateTime if necessary (although if your object really is "just a date" then LocalDate is the right object to use.

like image 64
JodaStephen Avatar answered Sep 27 '22 20:09

JodaStephen