DateTime.Ticks Propriedade

Definição

Obtém o número de tiques que representam a data e hora dessa instância.Gets the number of ticks that represent the date and time of this instance.

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

Valor da propriedade

O número de tiques que representam a data e hora dessa instância.The number of ticks that represent the date and time of this instance. O valor está entre DateTime.MinValue.Ticks e DateTime.MaxValue.Ticks.The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

Exemplos

O exemplo a seguir usa a propriedade Ticks para exibir o número de tiques que foram decorridos desde o início do século vinte e uma instanciar um objeto TimeSpan.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. O objeto TimeSpan é usado para exibir o tempo decorrido usando vários outros intervalos de tempo.The TimeSpan object is then used to display the elapsed time using several other time intervals.

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
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

Comentários

Um único tique representa 100 nanossegundos ou 1 10-milionésimo de um segundo.A single tick represents one hundred nanoseconds or one ten-millionth of a second. Há 10.000 tiques em um milissegundo ou 10 milhões tiques em um segundo.There are 10,000 ticks in a millisecond, or 10 million ticks in a second.

O valor dessa propriedade representa o número de intervalos de 100 a nanossegundos decorridos desde 12:00:00-noite, 1º de janeiro de 0001 no calendário gregoriano, que representa MinValue.The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 in the Gregorian calendar, which represents MinValue. Ele não inclui o número de tiques que podem ser atribuídas a segundos bissextos.It does not include the number of ticks that are attributable to leap seconds. Se o objeto DateTime tiver sua propriedade Kind definida como Local, seus tiques representarão o tempo decorrido desde 12:00:00-noite, 1 de Janeiro, 0001 na hora local, conforme especificado pela configuração de fuso horário atual.If the DateTime object has its Kind property set to Local, its ticks represent the time elapsed time since 12:00:00 midnight, January 1, 0001 in the local time as specified by the current time zone setting. Se o objeto DateTime tiver sua propriedade Kind definida como Utc, seus tiques representarão o tempo decorrido desde 12:00:00-noite, 1 de Janeiro, 0001 no tempo universal coordenado.If the DateTime object has its Kind property set to Utc, its ticks represent the time elapsed time since 12:00:00 midnight, January 1, 0001 in the Coordinated Universal Time. Se o objeto DateTime tiver sua propriedade Kind definida como Unspecified, seus tiques representarão o tempo decorrido desde 12:00:00-noite, 1º de janeiro de 0001 no fuso horário desconhecido.If the DateTime object has its Kind property set to Unspecified, its ticks represent the time elapsed time since 12:00:00 midnight, January 1, 0001 in the unknown time zone.

Em geral, os tiques representam a hora de acordo com o fuso horário especificado pela propriedade Kind.In general, the ticks represent the time according to the time zone specified by the Kind property.

Aplica-se a