Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting joda LocalTime to sql Time

Tags:

java

jodatime

I want to convert a LocalTime object to a java.sql.Time object.

java.sql.Time time = new java.sql.Time(new LocalTime(1,0,0,0).getMillisOfDay());
System.out.println(time); //20:00:00

The above code, instead of creating a Time object with a value equal to 01:00:00, creates an object with a time of 20:00:00. The local time is eastern time.

What steps should I take?

like image 494
pgerstoft Avatar asked Feb 23 '12 22:02

pgerstoft


1 Answers

Time(..) accepts a timestamp starting from 1970. So you should pass that:

new Time(new LocalTime(...).toDateTimeToday().getMillis())

like image 55
Bozho Avatar answered Sep 25 '22 02:09

Bozho