Last active
August 29, 2015 14:02
-
-
Save trcio/e6e26b7380be4642f7d8 to your computer and use it in GitHub Desktop.
Unix Timestamp for C#
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 UnixTime | |
{ | |
public static int Get() | |
{ | |
return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; | |
} | |
public static DateTime ToDateTime(int timestamp) | |
{ | |
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | |
return epoch.AddSeconds(timestamp).ToLocalTime(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment