I. Time Interval
/// <Summary> time interval </Summary>
/// <Param name = "datetime1"> first date and time </param>
/// <Param name = "datetime2"> Second Date and time </param>
/// <Returns> integer portion of minutes separated by the same day </returns>
Private int datediff (datetime datetime1, datetime datetime2)
{
Timespan ts1 = new timespan (datetime1.ticks );
Timespan ts2 = new timespan (datetime2.ticks );
Timespan Ts = ts1.subtract (ts2). duration ();
// Datediff = ts. Days. tostring () + "day"
// + Ts. Hours. tostring () + "hour"
// + Ts. Minutes. tostring () + "Minute"
// + Ts. Seconds. tostring () + "seconds ";
Return convert. toint32 (TS. totalminutes );
}
2. The time difference from the current time is several seconds
Datetime dt1 = datetime. now;
Datetime dt2 = datetime. now;
Timespan Ts = dt1.subtract (dt2). duration ();
Double doulen = ts. totalseconds;
3. Time Addition
//
time addition
//
//
// time and
private datetime datesum (datetime datetime1, datetime datetime2)
{< br> datetime1 = hour (datetime2.hour);
datetime1 = datetime1.addminutes (datetime2.minute);
datetime1 = datetime1.addseconds (datetime2.second );
return datetime1;
}