title: How can I convert a Unix timestamp to DateTime and vice versa?
body: <p>There is this example code, but then it starts talking about millisecond / nanosecond problems.</p>
  
  <p>The same question is on MSDN, <em><a href="https://docs.microsoft.com/archive/blogs/brada/seconds-since-the-unix-epoch-in-c" rel="noreferrer">Seconds since the Unix epoch in C#</a></em>.</p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>public Double CreatedEpoch
  {
    get
    {
      DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();
      TimeSpan span = (this.Created.ToLocalTime() - epoch);
      return span.TotalSeconds;
    }
    set
    {
      DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();
      this.Created = epoch.AddSeconds(value);
    }
  }
  </code></pre>