DateTimeOffset.Ticks プロパティ

定義

現在の DateTimeOffset オブジェクトの日時を表すタイマー刻み数を取得します。Gets the number of ticks that represents the date and time of the current DateTimeOffset object in clock time.

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

プロパティ値

DateTimeOffset オブジェクトの時刻のタイマー刻みの数。The number of ticks in the DateTimeOffset object's clock time.

次の例では、1:23:07 2008 年7月1日の日付のティック数を概算して DateTimeOffset オブジェクトを初期化します。The following example initializes a DateTimeOffset object by approximating the number of ticks in the date July 1, 2008 1:23:07. 次に、日付とその日付で表されるタイマー刻みの数がコンソールに表示されます。It then displays the date and the number of ticks represented by that date to 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
const long 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);
Console.WriteLine("There are {0:n0} ticks in {1}.", 
                  dto.Ticks, 
                  dto.ToString());
// The example displays the following output:
//       There are 633,504,721,870,000,000 ticks in 7/1/2008 1:23:07 AM -08:00.      
' 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
Const NSPerSecond As Long = 10000000
Dim ticks As Long
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      
Dim dto As DateTimeOffset = New DateTimeOffset( _
                            ticks, _
                            DateTimeOffset.Now.Offset)
Console.WriteLine("There are {0:n0} ticks in {1}.", _
                  dto.Ticks, _
                  dto.ToString())
' The example displays the following output:
'       There are 633,504,721,870,000,000 ticks in 7/1/2008 1:23:07 AM -08:00.      

注釈

Ticks プロパティは、Offset プロパティの値の影響を受けません。The Ticks property is not affected by the value of the Offset property.

Ticks プロパティの値は、0001年1月1日 (MinValueの値) に12:00:00 午前0時から経過した100ナノ秒間隔の数を表します。The value of the Ticks property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001 (the value of MinValue). これには、閏月によって追加されるティックは含まれません。It does not include ticks that would be added by leap seconds. ナノ秒の10億分は1秒です。1秒間に1000万タイマー刻みがあります。A nanosecond is one billionth of a second; there are ten million ticks in a second. Ticks プロパティの値は、DateTimeOffset.MinValue.Ticks から DateTimeOffset.MaxValue.Ticksまでの範囲です。The value of the Ticks property ranges from DateTimeOffset.MinValue.Ticks to DateTimeOffset.MaxValue.Ticks.

DateTimeOffset(Int64, TimeSpan) コンストラクターのオーバーロードを使用して、DateTimeOffset オブジェクトにタイマー刻みの数を割り当てることができます。You can assign the number of ticks to a DateTimeOffset object by using the DateTimeOffset(Int64, TimeSpan) constructor overload.

適用対象

こちらもご覧ください