C # interval calculation can be implemented through the timspan class of the time scale class, which is a system class.
C # example of interval calculation:
Implement the C # interval calculation between two times:
// Obtain the number of scales for the current time 1
Timespan ts1 = new timespan (datetime. Now. ticks );
// YourCodeOr other operations
// Obtain the number of scales for the current time 2
Timespan ts2 = new timespan (datetime. Now. ticks );
// Absolute value of time difference
Timespan Ts = ts2.subtract (ts1). duration ();
// Actual execution time in the format of X hour x minute x second
String spantime = ts. Hours. tostring () + "Hour" + ts. Minutes. tostring () + "Minute" + ts. Seconds. tostring () + "second ";
C # Time Interval calculation instructions:
The timespan value contains many attributes and methods for accessing or processing a timespan value.
The following list covers some of them:
Add: adds the value to another timespan value.
Days: returns the timespan value calculated by the number of days.
Duration: gets the absolute value of timespan.
Hours: returns the hourly timespan value.
Milliseconds: returns the timespan value in milliseconds.
Minutes: returns the timespan value calculated in minutes.
Negate: returns the opposite number of the current instance.
Seconds: returns the timespan value calculated in seconds.
Subtract: Subtract another timespan value from it.
Ticks: the number of tick values returned for timespan.
Totaldays: returns the number of days indicated by the timespan value.
Totalhours: returns the number of hours represented by the timespan value.
Totalmilliseconds: the number of milliseconds in which the timespan value is returned.
Totalminutes: returns the number of minutes represented by the timespan value.
Totalseconds: returns the number of seconds represented by the timespan value.