المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to convert unix time to datetime (C#) ?



C# Programming
05-07-2013, 09:33 AM
Is there any built in method (.Net C#) to convert the unix time (double datatype) to datetime?

I got the following code from Stackoverflow :

public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0);
dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
return dtDateTime;
}

But it's not working properly. The above method returns 1970-01-01 00:00:00 as result.

Thanks.

here is the Stackoverflow link:

http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa[^ (http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa)]