Created
April 19, 2016 22:51
-
-
Save musoftware/714239ac692cfa765d929f8f8c4eed99 to your computer and use it in GitHub Desktop.
Unix Timestamp Converter
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
internal static class UnixTimestampConverter | |
{ | |
public static DateTime Epoch | |
{ | |
get | |
{ | |
return new DateTime(1970, 1, 1, 0, 0, 0, 0); | |
} | |
} | |
public static DateTime ToDateTime(this uint unixTimestamp) | |
{ | |
return UnixTimestampConverter.Epoch.AddSeconds((double) unixTimestamp); | |
} | |
public static DateTime ToDateTime(this ulong unixTimestamp) | |
{ | |
return UnixTimestampConverter.Epoch.AddSeconds((double) unixTimestamp); | |
} | |
public static ulong ToUnixTime(this DateTime dateTime) | |
{ | |
return (ulong) (dateTime.ToUniversalTime() - UnixTimestampConverter.Epoch).TotalSeconds; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment