-
-
Save eneiasramos/566f3142bcec4cd50ddb353b7ec6b27f to your computer and use it in GitHub Desktop.
DateTime to epoch conversions for C#, UTC
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
using System; | |
namespace YourChoice | |
{ | |
public static class TimeHelpers | |
{ | |
public static DateTime FromEpochTime(this long unixTime) | |
{ | |
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | |
return epoch.AddSeconds(unixTime); | |
} | |
public static long ToEpochTime(this DateTime date) | |
{ | |
return (date.ToUniversalTime().Ticks - 621355968000000000) / 10000000; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment