1. There are two ways to calculate the time interval between two DateTimes:
1. Two DateTimes are subtracted directly to obtain a TimeSpan, indicating the interval between two times
2. Use the (DateTime) method to calculate, the result is the same as method 1, indicating that the time substituted by the parameter is subtracted by the current time, and a TimeSpan is returned.
2. The TimeSpan structure represents a time interval, measured by positive and negative days, hours, minutes, seconds and fractional parts of seconds.
TimeSpanThe text of the object (.tostring()) "11.13:46:40", which means 11 days, 13 hours, 46 minutes, and 40 seconds.
Properties: Gets the value of the current TimeSpan structure represented by the fractional part of the entire second and the second, which can be a negative number. It is about to convert days, hours, minutes, and seconds into seconds to display.
TimeSpan's Days, Hours, minutes, and seconds attributes: used to obtain the days, hours, minutes and seconds of the time interval respectively.
Here is an example: where the values of ts and ts2 are the same.
DateTime dTimeEnd = (examPeriod);
DateTime dTimeServer = ();
TimeSpan ts = dTimeEnd - dTimeServer;
TimeSpan ts2 = (dTimeServer);
(() + "\n" + ());
The above simple method (recommended) for calculating time intervals in C# is all the content I share with you. I hope you can give you a reference and I hope you can support me more.