How do I get epoch time in C#?

James Jeffery picture James Jeffery · Feb 26, 2012 · Viewed 117k times · Source

Possible Duplicate:
How do you convert epoch time in C#?

I'm trying to figure out how to get the epoch time in C#. Similar to the timestamps given on this website: http://www.epochconverter.com/

Does DateTime have a method for that?

Answer

Darin Dimitrov picture Darin Dimitrov · Feb 26, 2012
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int secondsSinceEpoch = (int)t.TotalSeconds;
Console.WriteLine(secondsSinceEpoch);