The following segment of code formats and converts a date to the UTC zone using the Joda-Time API.
DateTimeFormatter dateTimeFormatter=DateTimeFormat.forPattern("dd-MMM-yyyy hh:mm:ss aa");
DateTime dateTime = dateTimeFormatter.parseDateTime("15-Oct-2013 11:34:26 AM").withZone(DateTimeZone.UTC);
System.out.println(dateTime);
It displays the following date exactly as expected.
2013-10-15T06:04:26.000Z
But when this date is converted to java.sql.Timestamp
like so,
System.out.println(new Timestamp(dateTime.getMillis()));
it displays the following date.
2013-10-15 11:34:26.0
This means the same date/time as given. The time zone UTC appeared to be ignored.
How to get Timestamp
to correctly convert a date to UTC?