KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a java.util.Date object, and I need to insert it into a datetime field in MySQL in UTC format. java.util.Date date = myDateFromSomewhereElse; PreparedStatement prep = con.prepareStatement( "INSERT INTO table (t1, t2) VALUES (?,?)"); java.sql.Timestamp t = new Timestamp(date.getTime()); prep.setTimestamp(1, t, Calendar.getInstance(TimeZone.getTimeZone("PST")); prep.setTimestamp(2, t, Calendar.getInstance(TimeZone.getTimeZone("UTC")); System.out.println(prep.toString()); Which gives me the prepared SQL statement string: INSERT INTO table (t1, t2) VALUES ('2012-05-09 11:37:08','2012-05-09 11:37:08'); The timestamp returned is the same timestamp regardless of the timezone I specify. It's ignoring the Calendar object with timezone that I specify. What is going on and what am I doing wrong?
Tags (comma-separated)
Save Edits
Cancel