http://msdn.microsoft.com/zh-cn/library/system.datetimeoffset.ticks(VS.95).aspx

 

获取计时周期数,此计时周期数表示时钟时间中当前 DateTimeOffset 对象的日期和时间。

 

Ticks 属性不受 Offset 属性值的影响。

Ticks 属性的值表示自 0001 年 1 月 1 日午夜 12:00:00 以来所经历的以 100 纳秒为间隔的间隔数(DateTimeOffset.MaxValue.Ticks 之间。

通过使用 DateTimeOffset 对象。

 

下面的示例通过估计日期(2008 年 7 月 1 日 1:23:07)中的计时周期数来初始化 DateTimeOffset 对象。然后,它将该日期以及该日期所表示的计时周期数显示到控制台上。

// 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);
outputBlock.Text += String.Format("There are {0:n0} ticks in {1}.",
                  dto.Ticks,
                  dto.ToString()) + "\n";

相关文章:

  • 2022-01-27
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2021-05-08
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2021-08-30
  • 2021-10-05
  • 2021-12-21
  • 2022-12-23
相关资源
相似解决方案