Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
Created February 11, 2014 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisMcKee/8933245 to your computer and use it in GitHub Desktop.
Save ChrisMcKee/8933245 to your computer and use it in GitHub Desktop.
unix epoch helper
using System;
public static class UnixUtils
{
public static DateTime FromUnixTimeStamp(this Int64 unixTimestamp)
{
return new DateTime(1970, 1, 1).AddMilliseconds(unixTimestamp);
}
public static Int64 ToUnixTimeStamp(this DateTime date)
{
var epoc = new DateTime(1970, 1, 1);
var timeSpan = date - epoc;
return (long) timeSpan.TotalMilliseconds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment