title: Reading a formatted date as a Calendar or Date object in Java
body: <p>I'm trying to create a <code>Date</code> or <code>Calendar</code> object from a String representation of the date in Java. I tried using <code> SimpleDateFormat.parse</code>, but the result produced is totally different from what I gave as input. Can someone explain what I'm doing wrong here?</p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  import java.io.*;
  import java.text.*;
  class IdeOne
  {
    public static void main (String[] args) throws java.lang.Exception
    {
      SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMdd");
      sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date dt = sdf.parse("20141208");
      System.out.println(dt.getDay() + " " + dt.getMonth() + " " + dt.getYear());
      System.out.println(sdf.format(dt));
    }
  }
  </code></pre>
  
  <p>I am getting output</p>
  
  <pre><code>0 11 113
  20141229
  </code></pre>