When converting a string to a Joda DateTime in UTC based on a user's timezone and then converting it to a java.sql.Timestamp
, it changes back to eastern time.
DateTimeZone usersTimezone = DateTimeZone.forID("America/New_York");
String DATE_FORMAT = "MM/dd/yyyy hh:mm aa";
DateTimeFormatter DATETIME_FORMATTER = DateTimeFormat.forPattern(DATE_FORMAT);
DateTime date = DATETIME_FORMATTER.withZone(usersTimezone).parseDateTime("03/06/2016 5:30 AM");
DateTime utcDateTime = date.toDateTime(DateTimeZone.UTC);
java.sql.Timestamp utcTimestamp = new java.sql.Timestamp(utcDateTime.getMillis());
System.out.println(" UTC DATETIME: " + utcDateTime);
System.out.println("UTC TIMESTAMP: " + utcTimestamp);
Prints the following:
UTC DATETIME: 2016-03-06T10:30:00.000Z
UTC TIMESTAMP: 2016-03-06 05:30:00.0
Why does the timestamp convert back to Eastern time zone? I want to enter it in the database as a timestamp in UTC?
Note: Changing my server's timezone to UTC makes no difference.