Last active
February 27, 2019 10:54
-
-
Save guitarrapc/44f687da55126eb344316754e2b2e9fd to your computer and use it in GitHub Desktop.
UnixtimeStamp and .NET DateTime converter.
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
// if you are using .NET 4.6 and higher, use `DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()` | |
private double GetUnixTimeStamp(DateTime date) | |
{ | |
return date.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; | |
} | |
// if you are using .NET 4.6 and higher, use `DateTimeOffset.FromUnixTimeMilliseconds(unixtimestamp)` | |
private DateTime GetDateTime(double unixtimestamp) | |
{ | |
return new DateTime(1970, 1, 1).AddMilliseconds(unixtimestamp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment