C # Time Difference Calculation focus:
C # application of the time difference calculation function TimeSpan
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.
C # how to calculate the time difference:
- DateTime DateTime1,
- DateTime2 = DateTime. Now; // current time
- DateTime1 = Convert. ToDateTime ("20:00:00"); // set the required time minus
- StringDateDiff =Null;
- TimeSpan ts1 =NewTimeSpan (DateTime1.Ticks );
- TimeSpan ts2 =NewTimeSpan (DateTime2.Ticks );
- TimeSpan ts = ts1.Subtract (ts2). Duration ();
- // Display time
- DateDiff = ts. Days. ToString () + "day"
- + Ts. Hours. ToString () + "hour"
- + Ts. Minutes. ToString () + "Minute"
- + Ts. Seconds. ToString () + "Seconds ";