Skip to content

Instantly share code, notes, and snippets.

@terkhorn
Created November 7, 2012 19:55

Revisions

  1. terkhorn renamed this gist Nov 7, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. terkhorn created this gist Nov 7, 2012.
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    using System;

    namespace YourChoice
    {
    public static class TimeHelpers
    {
    public static DateTime FromEpochTime(this long unixTime)
    {
    var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    return epoch.AddSeconds(unixTime);
    }

    public static long ToEpochTime(this DateTime date)
    {
    return (date.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
    }
    }
    }