Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created October 20, 2014 01:40
Show Gist options
  • Save sandcastle/bdf4bf670bd7bd8a64f2 to your computer and use it in GitHub Desktop.
Save sandcastle/bdf4bf670bd7bd8a64f2 to your computer and use it in GitHub Desktop.
To Unix Time from DateTime
public static class TimeExtensions
{
// Good website for conversions:
// http://www.epochconverter.com/
// ToUnixTime(DateTime.Parse("20/10/2014 12:00:00 AM")) - should equal 1413734400
public static long ToUnixTime(this DateTime date)
{
return (date.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
}
}
@sandcastle
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment