I am getting time and the timezone of the time separately from a external component. The time is in the format 'MMM dd yyyy hh:mma'. Ex: Oct 31 2014 12:54PM and the timezone of this time is received separately.
I need to normalize this time to EST timezone before saving in the database. I tried Calendar(I don't think this can be done with java Date), but there were considerable inconsistencies with the output, and then after some googling, thought Joda had better support and switched to it. But I am getting the below exception.
String clientTimeZone = "America/New_York";
String value = "Nov 25 2014 2:18PM";
DateTimeFormatter df = DateTimeFormat.forPattern("MMM dd yyyy hh:mma");//.withLocale(Locale.ENGLISH);
DateTime temp = df.withZone(DateTimeZone.forID(clientTimeZone)).withOffsetParsed().parseDateTime(value);
DateTime date = temp.withZone(DateTimeZone.forID("America/New_York"));
Timestamp ts = new Timestamp(date.getMillis());
Date d = new Date(ts.getTime());
System.out.println(d.toString());
I got:
java.lang.IllegalArgumentException: Invalid format: "Nov 25 2014 2:18PM" is malformed at " 2:18PM" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899) at LearnJoda.main(LearnJoda.java:34)
Any idea on what could be the issue?