Compared to 1. Experiments comparing the size of time
String st1= "12:13";
String st2= "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;
Else
Msg. Text=st1+ "<" +ST2;
Msg. text+= "\ r \ n" +dt1. ToString ();
if (Datetime.compare (DT1,DT3) >0)
Msg. text+= "\ r \ n" +st1+ ">" +DT3. ToString ();
Else
Msg. text+= "\ r \ n" +st1+ "<" +DT3. ToString ();
2. A function that calculates two time difference values and returns the absolute value of the time lag:
private String DateDiff (DateTime datetime1,datetime DateTime2)
{
String Datediff=null;
Try
{
TimeSpan ts1=new TimeSpan (datetime1.ticks);
TimeSpan ts2=new TimeSpan (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
{
}
return DateDiff;
}
3. Realize the function of calculating datetime1-36 day =datetime2
TimeSpan ts=new TimeSpan (40,0,0,0);
DateTime dt2=datetime.now.subtract (TS);
Msg. Text=datetime.now.tostring () + "-" +ts. Days.tostring () + "days \ r \ n";
Msg. Text+=dt2. ToString ();