title: Java : Cannot format given Object as a Date
body: <p>I have Date in this format  (2012-11-17T00:00:00.000-05:00). I need to convert the date into this format mm/yyyy.</p>
  <p>I tried this way, but I am getting this Exception.</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.IllegalArgumentException: Cannot format given Object as a Date
      at java.text.DateFormat.format(Unknown Source)
      at java.text.Format.format(Unknown Source)
      at DateParser.main(DateParser.java:14)
  </code></pre>
  <p>Please see my code below:</p>
  <pre class="lang-java prettyprint-override"><code>import java.text.SimpleDateFormat;
  import java.util.Date;
  
  public class DateParser {    
    public static void main(String args[]) {   
      String MonthYear = null;    
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&quot;mm/yyyy&quot;);    
      String dateformat = &quot;2012-11-17T00:00:00.000-05:00&quot;;
      MonthYear = simpleDateFormat.format(dateformat);    
      System.out.println(MonthYear);    
    }    
  }
  </code></pre>