Created
February 11, 2014 11:34
-
-
Save ChrisMcKee/8933245 to your computer and use it in GitHub Desktop.
unix epoch helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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