Skip to content

Instantly share code, notes, and snippets.

@alexander-williamson
Created January 18, 2015 11:31
Show Gist options
  • Save alexander-williamson/e977f0ed4bd11bb6f3c7 to your computer and use it in GitHub Desktop.
Save alexander-williamson/e977f0ed4bd11bb6f3c7 to your computer and use it in GitHub Desktop.
public static class UnixTimestamp
{
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static double Convert(this DateTime dateTime)
{
return dateTime.Subtract(Epoch).TotalMilliseconds;
}
public static DateTime Convert(this double offset)
{
return Epoch.AddMilliseconds(offset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment