Archive

Posts Tagged ‘program’

Convert a Unix Time to a dot Net DateTime

May 7th, 2009 wiley No comments

I used *nix timestamp in my WEB project with MySQL database. To have a access via C# desktop program on timestamp datafield and vice versa i use this functions:

static DateTime ConvertFromUnixTimestamp(double timestamp)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}

static double ConvertToUnixTimestamp(DateTime date)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
return Math.Floor(diff.TotalSeconds);
}

Unique visitors to post: 0

Categories: C# Tags: , , , ,
Google Analytics integration offered by Wordpress Google Analytics Plugin