我有两个组合框,我希望用户在其中计算流程的总时间
I have two combo Boxes where I want users to calculate a total time for a process
//目前组合框的格式为 hh:mm,我知道我没有将它们从组合框正确转换为 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();
}
string format = "hh:mm"
DateTime dateTime = DateTime.ParseExact(comboBox.Text, format, CultureInfo.InvariantCulture);
尝试将其解析为 dateTime :)
顺便说一句,ComboBox.SelectedItem 不是 return 字符串,所以如果您不打算阅读文本 属性,请务必调用 SelectedItem.ToString() .
//目前组合框的格式为 hh:mm,我知道我没有将它们从组合框正确转换为 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();
}
string format = "hh:mm"
DateTime dateTime = DateTime.ParseExact(comboBox.Text, format, CultureInfo.InvariantCulture);
尝试将其解析为 dateTime :)
顺便说一句,ComboBox.SelectedItem 不是 return 字符串,所以如果您不打算阅读文本 属性,请务必调用 SelectedItem.ToString() .