源码如下:
int index = comboBox1.Items.ToString().IndexOf(":", 0);
string hours = comboBox1.Text.Substring(0, index - 1);
string minutes = comboBox1.Text.Substring(index + 1);
想通过用户选择的时间来制作倒数计数器;
取不到索引,index返回-1;
该如何修改或用其他什么办法。
谢谢叻!
int index = comboBox1.Items.ToString().IndexOf(":", 0);
string hours = comboBox1.Text.Substring(0, index - 1);
string minutes = comboBox1.Text.Substring(index + 1);
想通过用户选择的时间来制作倒数计数器;
取不到索引,index返回-1;
该如何修改或用其他什么办法。
谢谢叻!
comboBox1又是啥。
combox中是不是存的10:00这种形式的时间?然后当用户选中以后,算这个时间差?好吧,我就按照这个思路给你写!
DateTime index =Convert.ToDateTime( this.comboBox1.SelectedItem.ToString());
DateTime now=DateTime.Now;
TimeSpan a = new TimeSpan(index.Ticks).Subtract(new TimeSpan(now.Ticks)).Duration();
string datediff = a.Hours + "小时" + a.Minutes + "分钟";
MessageBox.Show(datediff);
学习了timespan、ticks和duration。
第一次来csdn,真稀奇。谢谢叻!