比较两台机器上的DateTime刻度 [英] Compare DateTime ticks on two machines

查看:77
本文介绍了比较两台机器上的DateTime刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在两个不同的计算机上比较两个文件的两个 FileInfo.CreationTimeUtc.Ticks 是一个可行的选择,以查看哪个版本较新-还是有更好的方法?

Is it a viable option to compare two FileInfo.CreationTimeUtc.Ticks of two files on two different computers to see which version is newer - or is there a better way?

滴答声是否取决于操作系统时间,或者它们是否确实是过去某个固定日期的物理滴答声?

Do Ticks depend on OS time or are they really physical ticks from some fixed date in the past?

推荐答案

简短的回答是,不,这不是一个可行的解决方案,至少在理论上,任何可能发生的类型的世界中都没有。

The short answer is that no, this is not a viable solution, at least not in the theoretical, anything-can-happen type of world.

一台计算机的时钟可能精确到十亿分之一秒,但问题不在于准确性,而是两台计算机的时钟是否同步。

The clock of a computer might be accurate to a billionth of a billionth of a second, but the problem isn't the accuracy, it's whether the clocks of the two computers are synchronized.

这里是一个实验。看你的手表,然后问一个随机的陌生人,你现在几点了。如果您在看表时将文件写入计算机,并在一秒钟前写入了您要问的人的计算机上,您的比较是否会确定您的文件或他/她的文件较新?

Here's an experiment. Look at your watch, then ask a random stranger around you what the time is. If your file was written to on your computer when you looked at the watch, and written to on the computer belonging to the person you're asking 1 second ago, would your comparison determine that your file or his/her file was newer?

现在,假设以下条件,您的解决方案可能会起作用:

Now, your solution might work, assuming that:


  • 您不是将不得不比较毫秒或纳秒级的不同时钟值

  • 有问题的计算机的时钟是与某些通用源
    **同步的,或者至少是同步的尽可能接近彼此,只要您的不准确标准允许

根据您的要求,我会认真考虑尝试查找另一种确保您获得正确价值的方法。

Depending on your requirements, I would seriously look at trying to find a different way of ensuring that you get the right value.

这篇关于比较两台机器上的DateTime刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆