C # TimeSpan days, Totaldays, Hours, totalhours, and other differences

Source: Internet
Author: User
In C # two time subtraction, get a TimeSpan instance, TimeSpan Some attributes: Days, Totaldays, Hours, Totalhours, Minutes, Totalminutes, Seconds, TotalSeconds, Ticks, note that there is no totalticks.

These attribute names begin to understand some difficulties, but after reading this article, you must be enlightened.

For example, Time 1 is 2010-1-2 8:43:35, time 2 is 2010-1-12 8:43:34.

With time 2 minus time 1, get a TimeSpan instance.

Then 2 times 1 more 9 days 23 hours 59 minutes 59 seconds.

Then, days is 9,hours is 23,minutes is 59,seconds is 59.

To see Ticks,tick is a time period, indicating 100 nanoseconds, that is, one out of 10,000 seconds, then Ticks here to indicate the total difference between the number of periods, namely: 9 * 24 * 3600 * 10000000 + 23 * 3600 * 10000000 + 59 * 60 * 10000000 + 59 * 10000000 = 8639990000000. 3600 is the number of seconds in an hour.

Totaldays is the Ticks conversion own number, namely: 8639990000000/(10000000 * 24 * 3600) = 9.99998842592593.

Totalhours is the conversion of Ticks into hours, that is: 8639990000000/(10000000 * 3600) = 239.999722222222.

Totalminutes is the conversion of Ticks into minutes, that is: 8639990000000/(10000000 * 60) = 14399.9833333333.

TotalSeconds is the conversion of Ticks into seconds, that is: 8639990000000/(10000000) = 863999.

Negative

The above is a late date minus an earlier date, so each property value is a positive number, and if the earlier date is a later date, the property value is negative.

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.