title: Get Date Object In UTC format in Java
body: <p>I have written following code. I want to get Date object in UTC format. </p>
  
  <p>I am able to get expected date string in UTC using <code>SimpleDateFormat</code>. But using same <code>SimpleDateFormat</code> object, I am not able to get object in UTC format. It is returning object with IST format.</p>
  
  <p>After searching, I found that Date object doesn't store timestamp info. </p>
  
  <p>How can I get date object in UTC format ?</p>
  
  <pre><code>import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.TimeZone;
  
  public class dddd {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          System.out.println("Input - "+1393572325000L);
          DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
          Date date= new Date(1393572325000L);  
          String dateString = formatter.format(date);
  
          System.out.println("Converted UTC TIME (using Format method) : "+dateString);
  
          Date date2 =null;
          try {
              date2 = formatter.parse(dateString);
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
  
          System.out.println("Parsed Date Object (using Parse method) : "+date2);
  
          System.out.println("Expected Date Object : Fri Feb 28 07:25:25 UTC 2014");
  
      }
  
  }
  </code></pre>
  
  <p>This prints following output :</p>
  
  <pre><code>Input - 1393572325000
  Converted UTC TIME (using Format method) : 2014-02-28 07:25:25
  Parsed Date Object (using Parse method) : Fri Feb 28 12:55:25 IST 2014
  Expected Date Object : Fri Feb 28 07:25:25 UTC 2014
  </code></pre>