时间字符串1:     “2:50:00”   即 2小时50分
 
时间字符串2:   “2.3”   即2小时18分时间字符串3:  “160 ”        即160分钟1和2 或者1和3 如何比较时间?

解决方案 »

  1.   

    转化成统一的类型!
    DateTime.CompareTo(要比较的时间);-1小于,0等于,1大于
      

  2.   

    string strTime1 = "2:50:00";
                string strTime2 = "2.3";
                string StrTime3 = "120";
                string [] arr1= strTime1.Split(':');
                float  time1Count=0;
                float time2Count = 0;
                float time3Count = Convert.ToInt32(StrTime3 );
                for (int i = 0; i < arr1.Length; i++)
                {
                    switch (i)
                    {
                        case 0:
                            time1Count +=Convert.ToInt32  ( arr1 [i ])*60;
                            break ;
                        case 1:
                            time1Count += Convert.ToInt32(arr1 [i]);
                            break;
                        case 2:
                            time1Count += float.Parse(arr1[i ]);
                            break;
                    }
                }
                time2Count = Convert.ToInt32(strTime2.Substring(0, 1)) * 60 + Convert.ToInt32(strTime2 .Substring (2,1))*6;
                //下面就可以比较time1Count,time2Cont,time3Cont