Created
September 22, 2015 15:28
-
-
Save pietrom/36bd3ef8604ffd8d9e72 to your computer and use it in GitHub Desktop.
DateTimeExtension
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
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