title: Joda TIme: can't format 12 hours datetime
body: <p>I'm trying to parse some dates that can be both 24 or 12 hours format using JodaTime. The 24-hours formatter works well, but when it comes to a 12-hours date it crashes with error:</p>
  
  <pre><code> java.lang.IllegalArgumentException: Invalid format: "10/14/2015 10:26:21 PM" is malformed at " PM"
  </code></pre>
  
  <p>I'm parsing dates that looks like this: "10/15/2015 04:46:32 PM"</p>
  
  <p>java code:</p>
  
  <pre><code>private final String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss";
  private final String DATE_FORMAT_12 = "MM/dd/yyyy hh:mm:ss aa";
  
  DateTimeFormatter dateStringFormat = null;
  String temp = jsonAlarm.getString("received_time_string");
  
  if(temp.contains("AM") || temp.contains("PM"))
      dateStringFormat = DateTimeFormat.forPattern(DATE_FORMAT_12);
  else
      dateStringFormat = DateTimeFormat.forPattern(DATE_FORMAT);
  
  if(!temp.equals(""))
      alarm.setReceivedTime(dateStringFormat.parseDateTime(temp));
  
  temp = jsonAlarm.getString("timestamp_string");
  
  if(temp.contains("AM") || temp.contains("PM"))
      dateStringFormat = DateTimeFormat.forPattern(DATE_FORMAT_12);
  else
      dateStringFormat = DateTimeFormat.forPattern(DATE_FORMAT);
  
  if(!temp.equals(""))
      alarm.setTimestamp(dateStringFormat.parseDateTime(temp));
  </code></pre>
  
  <p>the if statements that select the formatter works. so I don't what I'm doing wrong.</p>
  
  <p>please help
  thanks</p>
  
  <p>UPDATE: I checked the value of temp in debug and as far as I can see the "space" before PM is a proper space. also changing the if to <code>if(temp.contains(" AM") || temp.contains(" PM"))</code> works and correctly set the formatter with the 12 hours pattern</p>