Skip to content

Instantly share code, notes, and snippets.

@pietrom
Created September 22, 2015 15:28
Show Gist options
  • Save pietrom/36bd3ef8604ffd8d9e72 to your computer and use it in GitHub Desktop.
Save pietrom/36bd3ef8604ffd8d9e72 to your computer and use it in GitHub Desktop.
DateTimeExtension
public static class DateTimeExtension {
public static Int64 Epoch(this DateTime date)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return Convert.ToInt64((date - epoch).TotalMilliseconds) ;
}
public static DateTime ToDateTime(this long unixTime)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return epoch.AddMilliseconds(unixTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment