C# List to date time to listbox
I have a server with a .txt file. The program is saving the page to a
textfile and then it is being processed per line using count. I then need
to add it to datetime and then add it to a list.
So far it is pretty good except that last part datetime and the list. I
always get format exception. I have tried a few variations of try parse
and parse without luck.
The times are in a list like so: 06:06 AM 06:07 12:12 12:50
Message box shows each result at a time with no error and correct infomation.
while ((line = file.ReadLine()) != null)
{
// MessageBox.Show(line);
List<DateTime> Busarrivetime = new List<DateTime>();
// DateTime tryme = DateTime.Parse(line,
CultureInfo.InvariantCulture);
// MessageBox.Show(tryme.ToString());
DateTime date;
Busarrivetime.Add(date = DateTime.ParseExact(line,"hh:mm tt",
System.Globalization.CultureInfo.InvariantCulture)); // ERRORS
ON THIS LINE
count++;
}
file.Close();
Console.ReadLine();
No comments:
Post a Comment