DateTime.Ticks 属性

DateTime.Ticks 属性

获取表示此实例的日期和时间的计时周期数。

属性值
类型: System.Int64
表示此实例的日期和时间的计时周期数。 该值介于 DateTime.MinValue.Ticks 和 DateTime.MaxValue.Ticks 之间。 
备注
 

每个计时周期表示一百纳秒,即一千万分之一秒。 1 毫秒内有 10,000 个计时周期。

此属性的值表示自 0001 年 1 月 1 日午夜 12:00:00(表示 DateTime.MinValue)以来经过的以 100 纳秒为间隔的间隔数。 它不包括归因于闰秒的嘀嗒数。

示例
 

下面的示例使用 Ticks 属性显示自二十一世纪初以来经过的计时周期数,并实例化 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);
// If run on December 14, 2007, at 15:23, this example displays the
// following output to the console:
//    Elapsed from the beginning of the century to Friday, December 14, 2007 3:23 PM:
//          219,338,580,000,000,000 nanoseconds
//          2,193,385,800,000,000 ticks
//          219,338,580.00 seconds
//          3,655,643.00 minutes
//          2,538 days, 15 hours, 23 minutes, 0 seconds

转载于:https://www.cnblogs.com/jhxk/articles/4081678.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值