//目前combox的格式是hh:mm,我知道我没有将它们正确地转换为来自comboBoxes的DateTime.Parse,任何帮助都会很棒!!
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string start = comboBox2.SelectedItem;
starttime = DateTime.Parse(start);
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
string end = comboBox3.SelectedItem;
endtime = DateTime.Parse(end);
}
private void button2_Click(object sender, EventArgs e)
{
double z;
z = endtime - starttime;
textBox1.Text = z.ToString();
}
答案 0 :(得分:0)
string format = "hh:mm"
DateTime dateTime = DateTime.ParseExact(comboBox.Text, format, CultureInfo.InvariantCulture);
尝试将其解析为dateTime:)
顺便说一句,ComboBox.SelectedItem不返回字符串,因此如果您不打算读取Text属性,请确保调用SelectedItem.ToString()。