title: How do I get DateTimeFormat working with Spring MVC?
body: <p>I have a controller method that looks like this:</p>
  
  <pre><code>@RequestMapping(headers = "Accept=application/json;charset=utf-8", value = "/test", method = RequestMethod.GET)
      @ResponseBody
      public Blah test(@ModelAttribute MyObject parms, HttpServletRequest request) throws Exception { 
  
          // blah blah
      }
  </code></pre>
  
  <p>MyOBject looks like this:</p>
  
  <pre><code>public class MyObject{
  
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
      private Calendar someDate;
      // blah blah setters getters
  </code></pre>
  
  <p>When I call this method via browser like so:</p>
  
  <pre><code>http://localhost:8080/blah/test?someDate=2011-07-11T21%3A28%3A59.564%2B01%3A00
  </code></pre>
  
  <p>I am getting Error 400 - Bad Request.</p>
  
  <p>I kept trying with various different values for someDate (always using a URL encoder to encode the special chars) and nothing works.
  All the ones I tried (pre-URL encoding):</p>
  
  <p>2000-10-31 01:30:00.000-05:00  </p>
  
  <p>2011-07-11T21:28:59.564+01:00</p>
  
  <p>2014-04-23T13:49:28.600Z</p>
  
  <p>I know dates dont match I am merely trying to get Spring to parse this damn date for me into that Calendar object!! (Though really I would prefer it was a java.sql.Timestamp but that's probably even harder to get done)</p>
  
  <p>How do I do this?</p>
  
  <p>Am I writing the date wrong? 
  Am I using the wrong annotation for properties in a ModelAttribute (Note I have many other parameters so I bundle them up in a ModelAttribute object, dont want to use @RequestParm)</p>
  
  <p>The error that shows up in log file:</p>
  
  <pre><code>Field error in object 'myObject' on field 'someDate': rejected value [2011-07-11T21:28:59.564+01:00]; codes [typeMismatch.myObject.someDate,typeMismatch.someDate,typeMismatch.java.util.Calendar,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [myObject.someDate,someDate]; arguments []; default message [someDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Calendar' for property 'someDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat java.util.Calendar for value '2011-07-11T21:28:59.564+01:00'; nested exception is java.lang.IllegalArgumentException: Unable to parse '2011-07-11T21:28:59.564+01:00']
  </code></pre>