英語で読む

次の方法で共有


DateTime.Ticks プロパティ

定義

このインスタンスの日付と時刻を表すタイマー刻み数を取得します。

C#
public long Ticks { get; }

プロパティ値

このインスタンスの日付と時刻を表すタイマー刻み数。 値は DateTime.MinValue.Ticks から DateTime.MaxValue.Ticks までの間にあります。

次の例では、 プロパティを Ticks 使用して、21 世紀の初めから経過したティック数を表示し、オブジェクトを TimeSpan インスタンス化します。 オブジェクトは TimeSpan 、他のいくつかの時間間隔を使用して経過時間を表示するために使用されます。

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

注釈

1 ティックは、100 ナノ秒または 1,000 万分の 1 秒を表します。 1 ミリ秒に 10,000 ティック (参照 TicksPerMillisecond) があり、1 秒間に 1,000 万ティックがあります。

このプロパティの値は、グレゴリオ暦の 0001 年 1 月 1 日の午前 12 時 00 分から経過した 100 ナノ秒間隔の数を表します。これは を表します MinValue。 閏秒に起因するティック数は含まれません。 DateTime オブジェクトの プロパティが にLocal設定されている場合、ティックはKind、現在のタイム ゾーン設定で指定された現地時刻の 12:00:00 午前 0 時、0001 年 1 月 1 日からの経過時間を表します。 オブジェクトの DateTime プロパティが にUtc設定されている場合、そのティックはKind、協定世界時の 0001 年 1 月 1 日午前 0 時 00 分 00 分からの経過時間を表します。 オブジェクトの DateTime プロパティが にUnspecified設定されている場合、そのティックはKind、不明なタイム ゾーンの 0001 年 1 月 1 日の午前 0 時 00 分 00 分 12 時からの経過時間を表します。

一般に、ティックは、 プロパティで指定されたタイム ゾーンに従って時刻を Kind 表します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0