1. Calculate the time interval between two datetime values.Two methods:
1. Two datetime values are directly subtracted, and a timespan is obtained, indicating the interval between the two datetime values.
2. Use the datetime. Subtract (datetime) method for calculation. The result is the same as that of method 1, indicating that the current time is used minus the time entered by the parameter, and a timespan is returned.
II,TimespanThe structure indicates a time interval, which is measured by plus or minus days, hours, minutes, seconds, and decimals of seconds.
TimespanObject text (. tostring () "11.13: 46: 40", indicating 11 days, 13 hours, 46 minutes, and 40 seconds.
Timespan. totalseconds attribute: gets the value of the current timespan structure expressed in the integer and second decimal parts, which can be negative. Converts days, hours, minutes, And seconds to seconds for display.
The days, hours, minutes, And seconds attributes of timespan are used to obtain the days, hours, minutes, And seconds of the time interval.
The following is an example: TS and ts2.
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 ());