Return to Snippet

Revision: 22446
at January 12, 2010 18:57 by pckujawa


Initial Code
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1);
        const double MicrosecondsInAMillisecond = 1e3;

        public static ulong ToHawkTime(this DateTime value)
        {
            double d = (value - UnixEpoch).TotalMilliseconds * MicrosecondsInAMillisecond;
            return (ulong) d;
        }

        public static DateTime ConvertFromHawkTime(this ulong value)
        {
            DateTime d = UnixEpoch + TimeSpan.FromMilliseconds(value/MicrosecondsInAMillisecond);
            return d;
        }

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

Initial Description
Tentative source shows conversion to/from microseconds.

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

Initial Tags
date

Initial Language
C#