0

I have a java.sql.Timestamp variable in local timezone with following formatting

2011-07-21 00:40:37

I need to convert it to UTC

I asked this question to see if it can be done by mysql, but received no answers.

I guess I have to somehow do it in java code before substituting it in the query

3
  • stackoverflow.com/questions/2609360/… Already asked. Commented Jul 25, 2011 at 20:59
  • @Jon That won't work for me because it doesn't take into account the variable DST. This code will be deployed in multiple timezones and I will need it to be accurate in UTC conversion based on its location and time of year... Commented Jul 25, 2011 at 21:03
  • MySQL solution SELECT CONVERT_TZ( NOW(), @@session.time_zone, '+00:00' ) Commented Feb 14, 2012 at 16:54

1 Answer 1

2

I recommend using Joda Time to parse the timestamp. You'll need to set the timezone to EST and then get the UTC time from there. You could do the same thing with the generic Java Date, but Joda is easier to work with.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to read local timezone? EST was just an example, but it could be any timezone
After a closer look at Joda time I see it has public long convertLocalToUTC(long instantLocal, boolean strict) Looks like setting the strict argument to True will make it account for DST if applicable. Hopefully it will turn out to be exactly what I need. Won't know for sure until after QA's done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.