简体   繁体   中英

Not Recognized as a valid datetime. Unknown word starting at index 0

I am trying calculate the timespan between two listbox. This my code..

for (int x = 0; x < listBox1.Items.Count; x++)
{
    DateTime z = DateTime.Parse(listBox2.Items.ToString());
    DateTime c = DateTime.Parse(listBox3.Items.ToString());
    TimeSpan w = c - z;
}

Maybe you need some thing like this:

for (int x = 0; x < listBox1.Items.Count; x++)
{
    DateTime z = DateTime.Parse(listBox2.Items[x].ToString());
    DateTime c = DateTime.Parse(listBox3.Items[x].ToString());
    TimeSpan w = c.Subtract(z);
} 

Also, your ListBoxes items should be the same count

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM