Calculation of time difference in C #

xiaoxiao2021-03-06  146

Program code: label1.text = "2004-1-1 15:36:05"; label2.text = "2004-3-1 20:16:35"; DateTime D1 = New DateTime (2004, 1, 1, 15 , 36, 05); DateTime D2 = New DateTime (2004, 3, 1, 20, 16, 35); TimeSpan D3 = D2.Subtract (D1); label3.text = "Partial difference:" D3.Days.toString "Day" D3.Hours.Tostring () "Hours" D3.minutes.tostring () "Minute" D3.Seconds.toString () "Second";

code:

C # time period Timespan object's maximum spacing is the simple implementation as follows: system.datetime date1 = new system.datetime (1996, 6, 3, 22, 15); system.datetime date2 = new system.datetime 1996, 12, 6, 13, 2, 0); System.Datetime Date3 = New System.Datetime (1996, 10, 12, 8, 42, 0); // Diff1 Gets 185 Days, 14 Hours, And 47 Minutes. System.Timespan Diff1 = Date2.Subtract (Date1); // Date4 gets 4/9/1996 5:55:00 Pm.system.datetime Date4 = DATE3.SUBTRACT (DIFF1); // Diff2 Gets 55 Days 4 Hours and 20 Minutes.system.Timespan Diff2 = Date2 - Date3; // Date5 gets 4/9/1996 5:55:00 pm.system.datetime Date5 = DATE1 - DIFF2;

转载请注明原文地址:https://www.9cbs.com/read-127389.html

New Post(0)