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.
示例
下面的示例 DateTimeOffset 通过逼近 1:23:07 2008 年7月1日中的计时周期数来初始化一个对象。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日午夜12:00:00 日开始经过的100毫微秒时间间隔 () 的值 MinValue 。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. 毫微秒为一秒的十亿分之一;第二个计时周期为10000000。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 使用构造函数重载将计时周期数分配给对象 DateTimeOffset(Int64, TimeSpan) 。You can assign the number of ticks to a DateTimeOffset object by using the DateTimeOffset(Int64, TimeSpan) constructor overload.