title: How does Java's date work?
body: <p>Hi I have a following code below:</p>
  
  <pre><code>public Date convertFromGMTToLocal(Date date) {
       return new Date(date.getTimezoneOffset() + newOffset*60*1000);  
  }
  
  public Date convertFromLocalToGMT(Date date) {
      return new Date(date.getTime() - date.getTimezoneOffset()*60*1000);
  }
  </code></pre>
  
  <p>convertFromLocalToGMT is supposed to strip off timezone information and convertFromGMTToLocal is supposed to put the timezone information back. I understand java.util.Date is representing the time in epoch and always in GMT however when displaying the date it is defaulted to JVM's default timezone. </p>
  
  <p>Explanation I got was that if your timezone is CST and it is 10:00AM CST you are changing timezone to GMT with convertFromLocalToGMT so you're essentially adding the offset to get GMT so you get 4:00AM CST (offset is -6) and using convertFromGMTToLocal will <strong>convert this Date object back to 10:00AM regardless of your timezones</strong> (the most confusing part how?). How does above work? I am confused...</p>
  
  <p>Thanks.</p>