DateTime.Now.Ticks如何工作? [英] How does DateTime.Now.Ticks exactly work?
问题描述
在我的应用程序中,我随机生成文件。为了确保唯一的命名,我尝试使用自1970年1月1日以来的纳秒:
In my application I generate files at random opportunities. To ensure a unique naming, I tried to use the nano seconds since 1.1.1970:
long time = DateTime.Now.Ticks;
String fileName = Convert.ToString(time);
Console.WriteLine(fileName);
现在我观察到一些奇怪的东西。为什么这样的输出?我的意思是为什么最后4个数字总是相同?我可以使用它作为文件名,这不是问题,但我只是想知道。
Now I observed something weird. Why is the output like that? I mean why are the last 4 numbers always the same? I can use this as a filename, that is not the problem, but I'm just wondering about it.
634292263478068039
634292263512888039
634292263541368039
634292263603448039
634292263680078039
推荐答案
DateTime.Now
取决于您的系统计时器(在当前Windows操作系统上为〜10ms)...因此它在此处给出相同的结束值(它的计数没有比)。
The resolution of DateTime.Now
depends on your system timer (~10ms on a current Windows OS)...so it's giving the same ending value there (it doesn't count any more finite than that).
这篇关于DateTime.Now.Ticks如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!