TimeSpan usage
TimeSpan is used to represent an instance of a time period. The difference between two time periods can constitute a TimeSpan instance. Here are some important usage:
A first introduces several methods
TimeSpan. Minutes (other time, such as the number of days, Hours, and the number of seconds are the same.) Other Hours and Second are the same.
DateTime. Tick: it is a time cycle, which indicates one hundred nanoseconds, that is, one thousandth of a second. Here, Ticks indicates the total difference in time periods, that is, 9*24 * 3600*10000000 + 23*3600*10000000 + 59*60*10000000 + 59*10000000 = 8639990000000. 3600 is an hour In seconds
TimeSpan. TotalDays: the number of different days in two time periods, the same for other TotalHours, TotalMinutes, and TotalSeconds
B: difference in time
String time1 = "8:10:00 ";
String time2 = "18:20:00 ";
DateTime t1 = Convert. ToDateTime (time1 );
DateTime t2 = Convert. ToDateTime (time2 );
TimeSpan ts1 = t2-t1;
String tsMin = ts1.Minutes. ToString ();
TimeSpan ts11 = new TimeSpan (t1.Tick );
TimeSpan ts22 = new TimeSpan (t2.Tick );
String diff = ts22.Subtract (ts11). TotalMinutes. ToString ();
Subtract: the difference between two time periods.
Diff: represents the minutes of two different time periods. The example above is 610 minutes.
-- Cs code --
DateTime t1 = DateTime. Parse ("1998-2-25 ");
DateTime t2 = DateTime. Parse ("2009-7-28 ");
System. TimeSpan ts = t2-t1;
Int day = ts. Days;
-- SQL code --
Select year = datediff (year, '2014-2-25 ', '2014-7-28'), month = datediff (month, '2014-2-25 ', '2014-7-28 ')
Select month = datediff (month, '2017-2-25 ', '2017-7-28 ')
Select day = datediff (day, '2017-2-25 ', '2017-7-28 ')