title: Getting GMT time with Android
body: <p>I have been digging into the question for a while in StackOverflow
  <a href="https://stackoverflow.com/questions/2818086/android-get-current-utc-time">Android get Current UTC time</a>
  and
  <a href="https://stackoverflow.com/questions/308683/how-can-i-get-the-current-date-and-time-in-utc-or-gmt-in-java">How can I get the current date and time in UTC or GMT in Java?</a></p>
  
  <p>I have tried two ways to get the current time of my phone in GMT. I am in Spain and the difference is GMT+2. So let's see with an example:
  1º attemp: I created a format and applied it to System.currentTimeMillis();</p>
  
  <pre><code>    DateFormat dfgmt = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");   
      dfgmt.setTimeZone(TimeZone.getTimeZone("GMT")); 
      String gmtTime = dfgmt.format(new Date());
      //Using System.currentTimeMillis() is the same as new Date()
      Date dPhoneTime = dfgmt.parse(gmtTime);
      Long phoneTimeUTC = dPhoneTime.getTime();
  </code></pre>
  
  <p>I need to substract that time to another time, that's why i do the cast to Long.</p>
  
  <pre><code>    DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");          
      Date arrivalDate = df.parse(item.getArrivalDate());
      //the String comes from JSON and is for example:"UTC_arrival":"2011-05-16 18:00:00"
      //which already is in UTC format. So the DateFormat doesnt have the GMT paramater as dfgmt
      diff = arrival.getTime() - phoneTimeUTC ;
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>    Calendar aGMTCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
      Long phoneTimeUTC = aGMTCalendar.getTimeInMillis()
  </code></pre>
  
  <p>And still I dont get the right difference. But if I do this:</p>
  
  <pre><code>    Long phoneTimeUTC = aGMTCalendar.getTimeInMillis()-3600000*2;
  </code></pre>
  
  <p>It does work OK.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks a lot,</p>
  
  <p>David.</p>