1秒等于1000毫秒,以下单位是微秒、纳秒(=10亿秒)、皮秒、飞秒,均是千位进制。
为什么生成随机数时:Random ran = new Random((int)DateTime.Now.Ticks); 要用DateTime.Now.Ticks,DateTime.Now.Ticks的意义是什么?
获取表示此实例的日期和时间的刻度数。 ---是什么意思
计算机的“随机数”并非真的“随机数”,而是伪随机数——也就是通过一系列算法,从一个起始数字开始按照一定规则算出来的。
就好像函数F(x)一样,x就是随机数的种子。
你可以做个测试:把你的"new Random(x)"里面的x设置成一个固定数字,例如1,多次运行程序打印随机数,你会发现每次运行打印出来的数字都是一样的。
DateTime.Now.Ticks的刻度为一百纳秒。
取表示此实例的日期和时间的计时周期数。
属性值
类型: System..::.Int64表示此实例的日期和时间的计时周期数。该值介于 DateTime.MinValue.Ticks 和 DateTime.MaxValue.Ticks 之间。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
每个计时周期表示一百纳秒,即一千万分之一秒。此属性的值表示自 0001 年 1 月 1 日午夜 12:00:00(表示 DateTime..::.MinValue)以来经过的以 100 纳秒为间隔的间隔数。
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 //ticks*100=单位纳秒
// 2,193,385,800,000,000 ticks //单位ticks
// 219,338,580.00 seconds
// 3,655,643.00 minutes
// 2,538 days, 15 hours, 23 minutes, 0 seconds