DateTimeOffset: Ticks attribute

Source: Internet
Author: User

The http://msdn.microsoft.com/zh-cn/library/system.datetimeoffset.ticks (VS.95). aspx

 

Gets the number of time cycles, which indicates the date and time of the Current DateTimeOffset object in the clock time.

 

TicksThe property is not affected by the Offset property value.

TicksThe value of the attribute indicates the number of intervals (MinValue value) between January 1, 0001 nanoseconds that have elapsed since midnight, January 1, 100 .). One nanoseconds equals one thousandth of a second; one second includes 10 million time cycles.TicksThe property value isDateTimeOffset. MinValue. TicksAndDateTimeOffset. MaxValue. Ticks.

By using the DateTimeOffset (Int64, TimeSpan) constructor overload, you can allocate the number of time periods to the DateTimeOffset object.

 

The following example initializes the DateTimeOffset object by estimating the number of time cycles in the date (July 1, 2008 1:23:07. It then displays the date and the number of time cycles represented by the date on the console.

// Attempt to initialize date to number of ticks
// In July 1, 2008 1:23:07.
//
// There are 10,000,000 100-nanosecond intervals in a second
Constlong NSPerSecond = 10000000;
Long ticks;
Ticks = 7 * NSPerSecond; // Ticks in a 7 seconds
Ticks + = 23*60 * NSPerSecond; // Ticks in 23 minutes
Ticks + = 1*60*60 * NSPerSecond; // Ticks in 1 hour
Ticks + = 60*60*24 * NSPerSecond; // Ticks in 1 day
Ticks ++ = 181*60*60*24 * NSPerSecond; // Ticks in 6 months
Ticks + = 2007*60*60*24 * 365L * NSPerSecond; // Ticks in 2007 years
Ticks ++ = 486*60*60*24 * nspersecond; // adjustment for leap years
Datetimeoffset DTO = new datetimeoffset (
Ticks,
Datetimeoffset. Now. offset );
Outputblock. Text + = string. Format ("there are {0: N0} ticks in {1 }.",
Dto. ticks,
Dto. tostring () + "\ n ";

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.