Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eneiasramos/566f3142bcec4cd50ddb353b7ec6b27f to your computer and use it in GitHub Desktop.
Save eneiasramos/566f3142bcec4cd50ddb353b7ec6b27f to your computer and use it in GitHub Desktop.
DateTime to epoch conversions for C#, UTC
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