asp.net C # time Interval calculation method _ Practical skills

Source: Internet
Author: User
Tags time interval
C # time interval calculations illustrate:
To implement C # time interval calculations between two times:
TimeSpan ts1 = new TimeSpan (DateTime.Now.Ticks);
Gets the tick number of the current time//Your code or other operation TimeSpan ts2 = new TimeSpan (DateTime.Now.Ticks);
TimeSpan ts = ts2. Subtract (TS1). Duration ();
The absolute value of the time difference String spantime = ts. Hours.tostring () + "hour" + TS. Minutes.tostring () + "min" + TS. Seconds.tostring () + "seconds";
In X-hour x-seconds format Reality execution Time Some instructions for the C # time interval calculation:
The TimeSpan value contains a number of properties and methods that are used to access or process a TimeSpan value
The following list covers a subset of these:
Add: Adds to another timespan value.
Days: Returns the value of the timespan that is calculated in the day.
Duration: Gets the absolute value of the timespan.
Hours: Returns the timespan value calculated in hours
Milliseconds: Returns the TimeSpan value computed in milliseconds.
Minutes: Returns the timespan value calculated in minutes.
Negate: Returns the opposite number of the current instance.
Seconds: Returns the timespan value calculated in seconds.
Subtract: Subtracts another timespan value from it.
Ticks: Returns the number of tick for the timespan value.
Totaldays: Returns the number of days that the TimeSpan value represents.
Totalhours: Returns the number of hours represented by the timespan value.
TotalMilliseconds: Returns the number of milliseconds represented by the timespan value.
Totalminutes: Returns the number of minutes represented by the timespan value.
TotalSeconds: Returns the number of seconds represented by the timespan value
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.