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

مشاهدة النسخة كاملة : Convert Time



C# Programming
04-27-2009, 09:40 PM
I am trying to convert clock time to a double, and am getting an error, can someone use another pair of eyes to assist with this. See the code below. Thanks

static void Main(string[] args)
{
string[] timeArray = new string[6]{ "08:17", "15:26", "18:32", "00:46", "10:38", "13:56" };

double[] decTimeArray = new double[6];
for (int x = 0; x < timeArray.Length; x++)
{
decTimeArray[x] = ConvertTime(timeArray[x]);
}

for (int x = 0; x < timeArray.Length; x++)
{
Console.WriteLine(timeArray[x] + " " + decTimeArray[x]);
}
Console.ReadKey();
}
}

public static double ConvertTime(string rawTime)
{

int hours;
int minutes;
double dminutes;
double decimalTime;

string delimStr = ":";
char[] delimiter = delimStr.ToCharArray();
string[] split;
split = rawTime.Split(delimiter);
hours = Convert.ToInt32(split[0]);
minutes = Convert.ToInt32(split[1]);

if (minutes < 7)
dminutes = 0.00;
else if (minutes < 22)
dminutes = 0.25;
else if (minutes < 37)
dminutes = 0.50;
else if (minutes < 53)
dminutes = 0.75;
else dminutes = 1.0;
return decimalTime = dminutes + hours;