1. Comparison of time and size experiments
stringst1="12:13"; stringSt2="14:14"; DateTime DT1=Convert.todatetime (ST1); DateTime DT2=Convert.todatetime (ST2); DateTime DT3=DateTime.Now; if(Datetime.compare (DT1,DT2) >0) Msg. Text=st1+">"+St2; ElseMsg. Text=st1+"<"+St2; Msg. Text+="\ r \ n"+DT1. ToString (); if(Datetime.compare (DT1,DT3) >0) Msg. Text+="\ r \ n"+st1+">"+DT3. ToString (); ElseMsg. Text+="\ r \ n"+st1+"<"+dt3. ToString ();
2. Calculates the function of two time difference value, returns the absolute value of the time difference:
Private stringDateDiff (DateTime datetime1,datetime DateTime2) {stringdatediff=NULL; Try{TimeSpan Ts1=NewTimeSpan (datetime1.ticks); TimeSpan ts2=NewTimeSpan (datetime2.ticks); TimeSpan TS=Ts1. Subtract (TS2). Duration (); DateDiff=ts. Days.tostring () +"days"+ts. Hours.tostring () +"hours"+ts. Minutes.tostring () +"minutes"+ts. Seconds.tostring () +"seconds"; } Catch { } returnDateDiff; }
3. Realize the function of calculating datetime1-36 day =datetime2
TimeSpan ts=New TimeSpan (0,0,0); DateTime DT2=DateTime.Now.Subtract (ts); Msg. Text=datetime.now.tostring () +"-"+ts. Days.tostring () +" days \ r \ n"; Msg. Text
C # Compare time size 1, compare time size experiment