Original address: http://www.jb51.net/article/60177.htm
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text; namespaceTest {classProgram {Static voidMain (string[] args) {DateTime T1= DateTime.Parse ("2007-01-01"); DateTime T2= DateTime.Parse ("2006-01-01"); System.TimeSpan T3= T1-t2;//two time subtraction. By default, the number of days between two times is obtained: 365.00:00:00 DoubleGetDay = T3. Totaldays;//convert this number of days to days, the return value is double type (actually do not have to convert, because T3 default is the number of days) get: DoublegetHours = T3. TotalHours;//converts this number of days to hours, and the return value is a double of type DoubleGetminute = T3. Totalminutes;//convert this number of days to the component clock, the return value is double type Doublegetseconds = T3. TotalSeconds;//converts this number of days to seconds, and the return value is of type double. DoubleGetmillisecond = T3. TotalMilliseconds;////Converts this number of days to milliseconds, and the return value is of type doubleConsole.WriteLine (T3); //Output: 365.00:00:00Console.WriteLine (GetDay);//output: 365Console.WriteLine (getHours);//Output: 8760Console.WriteLine (Getminute);//Output: 525600Console.WriteLine (getseconds);//Output: 31536000Console.WriteLine (Getmillisecond);//Output: 31536000000Console.readkey (); } }}
C # two time subtraction