Posted By

pckujawa on 01/12/10


Tagged

time date epoch


Versions (?)

Working with Unix epoch in .NET (changing between DateTime and time since epoch)


 / Published in: C#
 

URL: http://blogs.msdn.com/brada/archive/2004/03/20/93332.aspx

Tentative source shows conversion to/from microseconds.

  1. private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1);
  2. const double MicrosecondsInAMillisecond = 1e3;
  3.  
  4. public static ulong ToHawkTime(this DateTime value)
  5. {
  6. double d = (value - UnixEpoch).TotalMilliseconds * MicrosecondsInAMillisecond;
  7. return (ulong) d;
  8. }
  9.  
  10. public static DateTime ConvertFromHawkTime(this ulong value)
  11. {
  12. DateTime d = UnixEpoch + TimeSpan.FromMilliseconds(value/MicrosecondsInAMillisecond);
  13. return d;
  14. }

Report this snippet  

You need to login to post a comment.