Example parsing of TimeSpan usage in ASP. NET, asp. nettimespan
The example in this article describes the usage of TimeSpan in ASP. NET and shares it with you for your reference. The details are as follows:
ASP. in. NET, two timespans are subtracted to get a TimeSpan instance. TimeSpan has some attributes: Days, TotalDays, Hours, TotalHours, Minutes, TotalMinutes, Seconds, TotalSeconds, and Ticks.
I. TimeSpan constants and fields
Copy codeThe Code is as follows: TimeSpan. MaxValue; // 10675199.02: 48: 05.4775807
TimeSpan. MinValue; //-10675199.02: 48: 05.4775808
TimeSpan. Zero; // 0.00: 00: 00.0
TimeSpan. TicksPerDay; // The number of ticks per day: 864000000000
TimeSpan. TicksPerHour; // The number of Tick in one hour: 36000000000
TimeSpan. TicksPerMillisecond; // The number of Tick data in one millisecond: 10000
TimeSpan. TicksPerMinute; // Number of Tick requests per minute: 600000000
TimeSpan. TicksPerSecond; // The number of Tick in one second: 10000000
Ii. Static TimeSpan Method
Copy codeThe Code is as follows: TimeSpan. Compare (); // comparison
TimeSpan. Equals (); // =
TimeSpan. FromDays (); // create from days
TimeSpan. FromHours (); // create
TimeSpan. FromMilliseconds (); // It is created in milliseconds.
TimeSpan. FromMinutes (); // create from the number of minutes
TimeSpan. FromSeconds (); // created in seconds
TimeSpan. FromTicks (); // create from the number of Tick
TimeSpan. Parse (); // create from string
TimeSpan. ParseExact (); // create a string in the specified format
TimeSpan. TryParse (); // try to create
TimeSpan. TryParseExact (); // try to create a string from the specified format
3. TimeSpan attributes
Copy codeThe Code is as follows: Days; // The day part of the Hours; // The Hour Part
Milliseconds; // millisecond part
Minutes; // parts
Seconds; // Seconds
Ticks; // total number of Tick
TotalDays; // Total Number of days
TotalHours; // total hours
TotalMilliseconds; // The total number of milliseconds
TotalMinutes; // The total number of minutes
TotalSeconds; // The total number of seconds.
Iv. TimeSpan Method
Copy codeThe Code is as follows: Add (); // + CompareTo (); // comparison
Duration (); // absolute value
Equals ();//
Negate (); // returns the inverse, +>-,-> +
Subtract (); //-, Add () Anti-manipulation
ToString (); // format it to a string. the. Net 4.0 version has changed from the previous version.
5. TimeSpan build object
Copy codeThe Code is as follows: protected void button#click (object sender, EventArgs e)
{
TimeSpan t1 = new TimeSpan (864000000000); // 1.00: 00: 00
TimeSpan t2 = new TimeSpan (23, 59, 59); // 23:59:59
TimeSpan t3 = new TimeSpan (30, 23, 59, 59); // 30.23: 59: 59
TimeSpan t4 = new TimeSpan (30, 23, 59, 59,999); // 30.23: 59: 59.9990000
Double f = 365.25;
TimeSpan t5 = TimeSpan. FromDays (f); // 365.06: 00: 00
TimeSpan t6 = TimeSpan. FromHours (f * 24); // 365.06: 00: 00
TimeSpan t7 = TimeSpan. FromMinutes (f * 24*60); // 365.06: 00: 00
TimeSpan t8 = TimeSpan. FromSeconds (f * 24*60*60); // 365.06: 00: 00
TimeSpan t9 = TimeSpan. FromMilliseconds (f * 24*60*60*1000); // 365.06: 00: 00
TimeSpan t0 = TimeSpan. FromTicks (long) (f * 24*60*60*1000*10000); // 365.06: 00: 00
TextBox1.Text = string. format ("{0} \ n {1} \ n {2} \ n {3} \ n {4} \ n {5} \ n {6} \ n {7} \ n {8} \ n {9 }",
T1, t2, t3, t4, t5, t6, t7, t8, t9, t0
);
}
Vi. TimeSpan instances
The time 1 is 8:43:35;
The time is 8:43:34.
Use Time 2 minus time 1 to get a TimeSpan instance.
Then the time 2 is 9 days, 23 hours, 59 minutes, and 59 seconds later than the time 1.
In this case, Days is 9, Hours is 23, Minutes is 59, and Seconds is 59.
Let's take a look at Ticks. Tick is a time cycle, which indicates one hundred nanoseconds, that is, one in one 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 the number of seconds in an hour.
TotalDays is to convert Ticks into the daily number, that is, 8639990000000/(10000000*24*3600) = 9.99998842592593.
TotalHours converts Ticks into hours, that is, 8639990000000/(10000000*3600) = 239.999722222222.
TotalMinutes converts Ticks to the number of minutes, that is, 8639990000000/(10000000*60) = 14399.9833333333.
TotalSeconds converts Ticks into seconds, that is, 8639990000000/(10000000) = 863999.
I hope this article will help you design your asp.net program.
Aspnet c # Calculate the time difference
TimeSpan in C #. after instantiation, values can be subtracted by two dates.
TimeSpan ts = new TimeSpan ();
Ts = DateTime1-DateTime2;
The structure of the TimeSpan object is: integer day, hh24: MM: dd.8-digit integer first three seconds
For example: {390.08: 43: 27.8437500}
The output differences are:
Ts. Hours8int
Ts. TotalHours9368.7244010416671double
(Int) ts. TotalHours9368
Aspnet: TimeSpan ts = new TimeSpan (3, 0, 30, 0); what is this write?
Defines a time difference. (3, 0, 30, 0) indicates 3 days, 0 hours, 30 minutes, 0 seconds.