C # example of interval calculation:
Implement the C # interval calculation between two times:
TimeSpan ts1 = new TimeSpan (DateTime. Now. Ticks );
// Obtain the number of scales for the current time // your code or other operations TimeSpan ts2 = new TimeSpan (DateTime. Now. Ticks );
TimeSpan ts = ts2.Subtract (ts1). Duration ();
// Absolute value of time difference String spanTime = ts. hours. toString () + "Hour" + ts. minutes. toString () + "Minute" + ts. seconds. toString () + "seconds ";
// The actual execution time is calculated in the format of X hour X minute X 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.