Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DateTime.Ticks Property

Gets the number of ticks that represent the date and time of this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public ReadOnly Property Ticks As Long

Property Value

Type: System.Int64
The number of ticks that represents the date and time of this instance. The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

The following example uses the Ticks property to display the number of ticks that have elapsed since the beginning of the twenty-first century and to instantiate a TimeSpan object. The TimeSpan object is then used to display the elapsed time using several other time intervals.


Dim centuryBegin As Date = #1/1/2001#
Dim currentDate As Date = Date.Now
Dim elapsedTicks As Long = currentDate.Ticks - centuryBegin.Ticks
Dim elapsedSpan As New TimeSpan(elapsedTicks)

outputBlock.Text += String.Format("Elapsed from the beginning of the century to {0:f}:", _
                   currentDate) & vbCrLf
outputBlock.Text += String.Format("   {0:N0} nanoseconds", elapsedTicks * 100) & vbCrLf
outputBlock.Text += String.Format("   {0:N0} ticks", elapsedTicks) & vbCrLf
outputBlock.Text += String.Format("   {0:N2} seconds", elapsedSpan.TotalSeconds) & vbCrLf
outputBlock.Text += String.Format("   {0:N2} minutes", elapsedSpan.TotalMinutes) & vbCrLf
outputBlock.Text += String.Format("   {0:N0} days, {1} hours, {2} minutes, {3} seconds", _
                  elapsedSpan.Days, elapsedSpan.Hours, _
                  elapsedSpan.Minutes, elapsedSpan.Seconds) & vbCrLf
' If run on December 14, 2007, at 15:23, this example displays the
' following output:
'          219,338,580,000,000,000 nanoseconds
'          2,193,385,800,000,000 ticks
'          219,338,580.00 seconds
'          3,655,643.00 minutes
'          2,538 days, 15 hours, 23 minutes, 0 seconds


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft