Created
December 8, 2022 03:19
-
-
Save CorbyO/c51ee97f9f00b7a48e724fb0b546fa7e to your computer and use it in GitHub Desktop.
C# UnixTime convert functions for DateTime
This file contains 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 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