java - How to convert Joda DateTime to UTC MySql timestamp -


i have joda datetime object representing utc time, , wish store in timestamp field in mysql table.

i have following code:

string ztime = "2013-10-07t08:00:00z";    datetimeformatter parser = isodatetimeformat.datetimeparser(); datetime dt = parser.parsedatetime(ztime).withzone(datetimezone.utc);  preparedstatement stmt = con.preparestatement("insert time_test (time) values (?)"); stmt.settimestamp(1, timestamp(dt.getmillis())); stmt.execute(); 

however, when in database, time gets store out difference of database's timezone utc. e.g. when database running in utc+1, , run above code save "08:00z", in database timestamp shows 09:00.

datetime's getmillis method says " gets milliseconds of datetime instant java epoch of 1970-01-01t00:00:00z." , mysql's timestamp says: "mysql converts timestamp values current time zone utc storage, , utc current time zone retrieval.", presume it's mysql conversion that's causing issue, because millis it's being initialized relative fixed utc time, has no need convert current time zone utc.

my code read data out datetime works fine, , value out put in, need work 3rd-party code on have no control, expects timestamp in correct utc time.

how timestamp field in database match original utc date/time ?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -