DateTime.Ticks 속성

정의

이 인스턴스의 날짜와 시간을 나타내는 틱 수를 가져옵니다.

public:
 property long Ticks { long get(); };
public long Ticks { get; }
member this.Ticks : int64
Public ReadOnly Property Ticks As Long

속성 값

이 인스턴스의 날짜와 시간을 나타내는 틱 수입니다. 값은 DateTime.MinValue.TicksDateTime.MaxValue.Ticks 사이입니다.

예제

다음 예제에서는 속성을 사용 하 여 Ticks 21 세기의 시작부터 경과 된 틱 수를 표시 하 고 개체를 TimeSpan 인스턴스화 합니다. 그런 다음 개체를 TimeSpan 사용하여 다른 여러 시간 간격을 사용하여 경과된 시간을 표시합니다.

DateTime centuryBegin = new DateTime(2001, 1, 1);
DateTime currentDate = DateTime.Now;

long elapsedTicks = currentDate.Ticks - centuryBegin.Ticks;
TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

Console.WriteLine("Elapsed from the beginning of the century to {0:f}:",
                   currentDate);
Console.WriteLine("   {0:N0} nanoseconds", elapsedTicks * 100);
Console.WriteLine("   {0:N0} ticks", elapsedTicks);
Console.WriteLine("   {0:N2} seconds", elapsedSpan.TotalSeconds);
Console.WriteLine("   {0:N2} minutes", elapsedSpan.TotalMinutes);
Console.WriteLine("   {0:N0} days, {1} hours, {2} minutes, {3} seconds",
                  elapsedSpan.Days, elapsedSpan.Hours,
                  elapsedSpan.Minutes, elapsedSpan.Seconds);

// This example displays an output similar to the following:
//
// Elapsed from the beginning of the century to Thursday, 14 November 2019 18:21:
//    595,448,498,171,000,000 nanoseconds
//    5,954,484,981,710,000 ticks
//    595,448,498.17 seconds
//    9,924,141.64 minutes
//    6,891 days, 18 hours, 21 minutes, 38 seconds
open System

let centuryBegin = DateTime(2001, 1, 1)
let currentDate = DateTime.Now

let elapsedTicks = currentDate.Ticks - centuryBegin.Ticks
let elapsedSpan = TimeSpan elapsedTicks

printfn $"Elapsed from the beginning of the century to {currentDate:f}:"
printfn $"   {elapsedTicks * 100L:N0} nanoseconds"
printfn $"   {elapsedTicks:N0} ticks"
printfn $"   {elapsedSpan.TotalSeconds:N2} seconds"
printfn $"   {elapsedSpan.TotalMinutes:N2} minutes"
printfn $"   {elapsedSpan.Days:N0} days, {elapsedSpan.Hours} hours, {elapsedSpan.Minutes} minutes, {elapsedSpan.Seconds} seconds"

// This example displays an output similar to the following:
//
// Elapsed from the beginning of the century to Thursday, 14 November 2019 18:21:
//    595,448,498,171,000,000 nanoseconds
//    5,954,484,981,710,000 ticks
//    595,448,498.17 seconds
//    9,924,141.64 minutes
//    6,891 days, 18 hours, 21 minutes, 38 seconds
Dim centuryBegin As Date = #1/1/2001 0:0:0#
Dim currentDate As Date = Date.Now
Dim elapsedTicks As Long = currentDate.Ticks - centuryBegin.Ticks
Dim elapsedSpan As New TimeSpan(elapsedTicks)

Console.WriteLine("Elapsed from the beginning of the century to {0:f}:", _
                   currentDate)
Console.WriteLine("   {0:N0} nanoseconds", elapsedTicks * 100)
Console.WriteLine("   {0:N0} ticks", elapsedTicks)
Console.WriteLine("   {0:N2} seconds", elapsedSpan.TotalSeconds)
Console.WriteLine("   {0:N2} minutes", elapsedSpan.TotalMinutes)
Console.WriteLine("   {0:N0} days, {1} hours, {2} minutes, {3} seconds", _
                  elapsedSpan.Days, elapsedSpan.Hours, _
                  elapsedSpan.Minutes, elapsedSpan.Seconds)
' If run on December 14, 2007, at 15:23, this example displays the
' following output to the console:
'          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

설명

틱 하나는 100나노초 또는 1/1000만 초를 나타냅니다. 밀리초 안에 10,000개의 틱(참조 TicksPerMillisecond)과 초당 1,000만 개의 틱이 있습니다.

이 속성의 값은 을 나타내는 그레고리오력의 0001년 1월 1일 자정 12:00:00 이후 경과된 100나노초 간격의 수를 나타냅니다 MinValue. 윤초에 귀속되는 틱 수는 포함되지 않습니다. DateTime 개체의 속성이 로 설정된 Local경우 해당 틱은 Kind 현재 표준 시간대 설정에 지정된 대로 현지 시간으로 0001년 1월 1일 자정 12:00:00 이후 경과된 시간을 나타냅니다. 개체의 DateTime 속성이 로 설정된 Utc경우 해당 틱은 Kind 협정 세계시에서 0001년 1월 1일 자정 12:00:00 이후 경과된 시간을 나타냅니다. 개체의 DateTime 속성이 로 설정된 Unspecified경우 해당 틱은 Kind 알 수 없는 표준 시간대의 0001년 1월 1일 자정 12:00:00 이후 경과 시간을 나타냅니다.

일반적으로 틱은 속성에 지정된 Kind 표준 시간대에 따라 시간을 나타냅니다.

적용 대상