我有一个带有 .txt 文件的服务器。该程序将页面保存到文本文件中,然后使用 count 每行处理它。然后我需要将其添加到日期时间,然后将其添加到列表中。
到目前为止,除了最后一部分日期时间和列表之外,它还不错。我总是得到格式异常。我尝试了一些尝试解析和解析的变体,但没有运气。
时间在这样的列表中:
06:06 AM
06:07
12:12
12:50
每行一个
消息框一次显示每个结果,没有错误和正确的信息。
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();
确切的错误:
mscorlib.dll 中出现“System.FormatException”类型的未处理异常