Skip to content

Instantly share code, notes, and snippets.

@trcio
Last active August 29, 2015 14:02
Show Gist options
  • Save trcio/e6e26b7380be4642f7d8 to your computer and use it in GitHub Desktop.
Save trcio/e6e26b7380be4642f7d8 to your computer and use it in GitHub Desktop.
Unix Timestamp for C#
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