Skip to content

Instantly share code, notes, and snippets.

@ubergoober
Created May 7, 2014 17:39
Show Gist options
  • Save ubergoober/5ac490dbb2e5188d8b98 to your computer and use it in GitHub Desktop.
Save ubergoober/5ac490dbb2e5188d8b98 to your computer and use it in GitHub Desktop.
Convert CurrentDateTime to Epoch in C#
public long GetEpochTime() {
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment