Last active
August 2, 2016 16:53
-
-
Save MiguelTVMS/5d58623d44ce5b8cc7174c6d2deedba9 to your computer and use it in GitHub Desktop.
DateTimeExtensions for C#
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
public static class DateTimeExtensions | |
{ | |
public static long ToUnixTime(this DateTime datetime) | |
{ | |
DateTime epochDate = new DateTime(1970, 1, 1,0,0,0,DateTimeKind.Utc); | |
return (long)(datetime - epochDate).TotalSeconds; | |
} | |
public static long ToJavaTime(this DateTime datetime) | |
{ | |
var epochTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks; | |
return (long)((datetime.ToUniversalTime().Ticks - epochTicks) / 10000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment