在处理工时的时候需要这样处理问题.
启动时间 结束时间 就需要处理多少小时,多少分钟等
写了一个函数处理
protected decimal GetSpanTime(TextBox txtstarttime, TextBox txtendtime)
{
int year = int.Parse(txtstarttime.Text.ToString().Substring(0, 4));
int month = int.Parse(txtstarttime.Text.ToString().Substring(4, 2));
int day = int.Parse(txtstarttime.Text.ToString().Substring(6, 2));
int hour = int.Parse(txtstarttime.Text.ToString().Substring(8, 2));
int min = int.Parse(txtstarttime.Text.ToString().Substring(10, 2));
int second = int.Parse(txtstarttime.Text.ToString().Substring(12, 2));
int year2 = int.Parse(txtendtime.Text.ToString().Substring(0, 4));
int month2 = int.Parse(txtendtime.Text.ToString().Substring(4, 2));
int day2 = int.Parse(txtendtime.Text.ToString().Substring(6, 2));
int hour2 = int.Parse(txtendtime.Text.ToString().Substring(8, 2));
int min2 = int.Parse(txtendtime.Text.ToString().Substring(10, 2));
int second2 = int.Parse(txtendtime.Text.ToString().Substring(12, 2));
DateTime t1 = new DateTime(year, month, day, hour, min, second);
DateTime t2 = new DateTime(year2, month2, day2, hour2, min2, second2);
TimeSpan diff = t2 - t1;
decimal h = decimal.Parse(diff.Minutes.ToString()) / 60;
decimal h2 = decimal.Round(h, 4);
return h2;
}