First, there are two ways to calculate the time interval for two datetime:
1, two datetime direct subtraction, get a timespan, representing two time interval
2, with the Datetime.subtract (DateTime) method of calculation, the result is the same as the method 1, indicating that the current time minus the time of the parameter, return a TimeSpan
The timespan structure represents a time interval, measured by positive and negative days, hours, minutes, seconds, and decimal parts of seconds.
The text of the TimeSpan object (. ToString ()) "11.13:46:40", representing 11 days, 13 hours, 46 minutes, and 40 seconds.
Timespan.totalseconds property: Gets the value of the current TimeSpan structure, expressed as a fraction of the integer seconds and seconds, to a negative number. The days, hours, minutes, and seconds are converted to seconds to display.
TimeSpan days, Hours, minutes, seconds attributes: To obtain the day, hour, minute, and second of the time interval, respectively.
Here is an example: the values for TS and TS2 are the same.
DateTime dtimeend = examairtime.addminutes (examperiod);
DateTime dtimeserver = Dataclass.getdateserver ();
TimeSpan ts = dtimeend-dtimeserver;
TimeSpan ts2 = dtimeend.subtract (dtimeserver);
MessageBox.Show (TS. ToString () + "\ n" + ts2. Totalminutes.tostring ());
The above C # calculation of the time interval of the simple method (recommended) is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.