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

مشاهدة النسخة كاملة : Convert String To Unix Timestamp



C# Programming
08-05-2009, 03:00 PM
well i have a string which contains a unix timestamp.
when i try to convert the string to either a double or a int, it gives me an error.
im out of ideas, i dont know how to get the string into a int or double, so i can convert it from unix to datetime.

here is my code:

string validstrStart = "validuntil=";
string validstrEnd = "username=";
int validstartIndex = result.IndexOf(validstrStart);
int validendIndex = result.IndexOf(validstrEnd);
string valid = result.Substring(validstartIndex, validendIndex - validstartIndex);

double timestampv = Convert.ToDouble(valid);
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddSeconds(timestampv);
string validpro = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString();

it gives me an error in this line:

double timestampv = Convert.ToDouble(valid);

same thing when i try with an int.

any help please :D