Skip to content

Instantly share code, notes, and snippets.

@CorbyO
Created December 8, 2022 03:19
Show Gist options
  • Save CorbyO/c51ee97f9f00b7a48e724fb0b546fa7e to your computer and use it in GitHub Desktop.
Save CorbyO/c51ee97f9f00b7a48e724fb0b546fa7e to your computer and use it in GitHub Desktop.
C# UnixTime convert functions for DateTime
public static int ToUnixTime(this DateTime dateTime)
{
return (int)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
}
public static DateTime ToDateTime(this Int32 unixTime)
{
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment