title: Unix time conversions in C#
body: <p>I am trying to get the GMT in unix time. I use the following code:</p>
  
  <pre>
  <code>
          public static long GetGMTInMS()
          {
              var unixTime = DateTime.Now.ToUniversalTime() -
                  new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  
              return (long)unixTime.TotalMilliseconds;
          }
  </code>
  </pre>
  
  <p>To then convert the unix time back to a DatTime object, I use this:</p>
  
  <pre>
  <code>
          public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
          {
              System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
              dtDateTime = dtDateTime.AddMilliseconds(unixTimeStamp).ToLocalTime();
              return dtDateTime;
          }
  </code>
  </pre>
  
  <p>When I run it, the <code>GetGMTInMS()</code> <code>1320249196267</code>. When I pass it to <code>UnixTimeStampToDateTime()</code> I get <code>{11/2/2011 11:53:16 AM}</code></p>
  
  <p>Which is fine. That is the correct time fro when I ran my code. The issue I have is when I try and put <code>1320249196267</code> into an unix time converter, such as <a href="http://www.onlineconversion.com/unix_time.htm" rel="noreferrer">this</a>, it returns the totally wrong time.</p>
  
  <p>The other issue, is i am in the eastern time zone. This returned the time in my time zone. Is this something that the <code>DateTime</code> object handles or am I not getting the GMT.</p>