Asp.net C # Time Interval Calculation Method

Source: Internet
Author: User

C # example of interval calculation:
Implement the C # interval calculation between two times:
Timespan ts1 = new timespan (datetime. Now. ticks );
// Obtain the number of scales for the current time // your Code Or other operations: timespan ts2 = new timespan (datetime. Now. ticks );
Timespan Ts = ts2.subtract (ts1). duration ();
// Absolute value of time difference string spantime = ts. hours. tostring () + "Hour" + ts. minutes. tostring () + "Minute" + ts. seconds. tostring () + "seconds ";
// The actual execution time is calculated in the format of X hour x minute x second C # Time Interval calculation instructions:
The timespan value contains many attributes and methods for accessing or processing a timespan value.
The following list covers some of them:
Add: adds the value to another timespan value.
Days: returns the timespan value calculated by the number of days.
Duration: gets the absolute value of timespan.
Hours: returns the hourly timespan value.
Milliseconds: returns the timespan value 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: Subtract another timespan value from it.
Ticks: the number of tick values returned for timespan.
Totaldays: returns the number of days indicated by the timespan value.
Totalhours: returns the number of hours represented by the timespan value.
Totalmilliseconds: the number of milliseconds in which the timespan value is returned.
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.