DateTimeOffset.Ticks プロパティ

定義

現在の DateTimeOffset オブジェクトの日時を表すタイマー刻み数を取得します。

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

プロパティ値

DateTimeOffset オブジェクトの時刻のタイマー刻みの数。

次の例では、 DateTimeOffset 2008 年 7 月 1 日 1:23:07 の日付のティック数を近似して、オブジェクトを初期化します。 次に、その日付で表される日付とティック数がコンソールに表示されます。

// 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
let NSPerSecond = 10000000L
let ticks = 7L * NSPerSecond                                  // Ticks in a 7 seconds
let ticks = ticks + 23L * 60L * NSPerSecond                   // Ticks in 23 minutes
let ticks = ticks + 1L * 60L * 60L * NSPerSecond              // Ticks in 1 hour
let ticks = ticks + 60L * 60L * 24L * NSPerSecond             // Ticks in 1 day
let ticks = ticks + 181L * 60L * 60L * 24L * NSPerSecond      // Ticks in 6 months
let ticks = ticks + 2007L * 60L * 60L * 24L * 365L * NSPerSecond   // Ticks in 2007 years
let ticks = ticks + 486L * 60L * 60L * 24L * NSPerSecond      // Adjustment for leap years
let dto = DateTimeOffset(ticks, DateTimeOffset.Now.Offset)
printfn $"There are {ticks:n0} ticks in {dto}."

// 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 受けません。

プロパティの Ticks 値は、0001 年 1 月 1 日午前 12 時 00 分 00 分から経過した 100 ナノ秒間隔の数 (の MinValue値) を表します。 うるう秒で追加されるティックは含まれません。 ナノ秒は 10 億分の 1 秒です。1 秒間に 1,000 万ティックがあります。 プロパティの値の Ticks 範囲は から DateTimeOffset.MinValue.TicksDateTimeOffset.MaxValue.Ticksです。

コンストラクター のオーバーロードを使用して、 DateTimeOffset オブジェクトにティック数を DateTimeOffset(Int64, TimeSpan) 割り当てることができます。

適用対象

こちらもご覧ください