symbol heatxsink.com blog  ·  archive  ·  about  ·  Feed feed

Unix Epoch

Tuesday, February 06, 2007 01:44 AM

The fun part of interoperating between the Windows, and Linux worlds is dealing with old skool and sometimes very ghetto standards. One which every programmer knows is storing date/time information in an epoch. The one most commonly used epoch is the unix epoch. In .NET they came up with a very cleaver way of dealing with Dates and Times via the DateTime class. Below is a code snippet in C# that I use to handle date/time information stored in unix epoch.

DateTime unixEpoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
DateTime someDate = DateTime.UtcNow;
TimeSpan span = someDate - unixEpoch;
int timestamp = (int) span.TotalSeconds;