title: Change the date time format of an existing DateTime instance of Joda
body: <p>I have two date fields. A user can choose a date from a jQuery date-time picker which is then converted into the UTC format (via a custom property editor of Spring) and populated into a Java bean upon the submission of the form.</p>
  
  <p>These <code>DateTime</code> instances from the Java bean are retrieved by <a href="http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/PropertyUtils.html" rel="nofollow"><code>org.apache.commons.beanutils.PropertyUtils</code></a> via reflection like,</p>
  
  <pre><code>final Object object1 = PropertyUtils.getProperty(beanObject, firstDate);
  final Object object2 = PropertyUtils.getProperty(beanObject, secondDate);
  </code></pre>
  
  <p>These objects are type-cast to <code>DateTime</code>.</p>
  
  <pre><code>if(object1!=null &amp;&amp; object2!=null)
  {
      final DateTime startDate=((DateTime)object1).withZone(DateTimeZone.forID("Asia/Kolkata"));
      final DateTime endDate=((DateTime)object2).withZone(DateTimeZone.forID("Asia/Kolkata"));
  
      System.out.println("startDate = "+startDate+"\nendDate = "+endDate);
  }
  </code></pre>
  
  <p>This produces the following output.</p>
  
  <pre><code>startDate = 2013-02-17T22:45:59.000+05:30
  endDate = 2013-02-18T22:46:00.000+05:30
  </code></pre>
  
  <p>I need to conver these dates into this format - <code>dd-MMM-yyyy HH:mm:ss</code></p>
  
  <p>The following approach which I have tried doesn't work.</p>
  
  <pre><code>DateTime newStartDate=new DateTime(startDate.toString("dd-MMM-yyyy HH:mm:ss"));
  DateTime newEndDate=new DateTime(startDate.toString("dd-MMM-yyyy HH:mm:ss"));
  
  System.out.println("newStartDate = "+newStartDate+"\nnewEndDate = "+newEndDate);
  </code></pre>
  
  <p>It gives the following exception.</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Invalid format: "17-Feb-2013
    22:45:59" is malformed at "-Feb-2013 22:45:59"</p>
  </blockquote>
  
  <p>So how to convert these dates into the required format?</p>