-2

DateTime.Now 返回当前日期。但如果有人更改了系统日期,DataTime.Now 实际上不会返回真正的当前数据。

所以问题是,计算机中是否有某个地方(可能是处理器或......)始终保存实际日期?如果是,我们如何检索这些数据。请假设应用程序无法访问互联网和本地网络(完全断开连接)。

4

3 回答 3

7

No.

There are precisely two ways to get the current time:

  1. Check the time on the computer
  2. Getting it from an external server (e.g. Internet, local network, some sort of radio broadcast...)

If you do not trust the time set on the computer itself, then your only option is the second one, and that necessarily requires a connection to a device where you can trust the system time.

于 2013-10-30T09:49:12.173 回答
1

No, there is no magic clock in computers that holds the correct time.

If you are interested in correct times you should look into NTP (network time protokol).

于 2013-10-30T09:50:03.927 回答
1

问题当然在于“真实”日期或时间的定义。

也许OP对这意味着什么有一个清晰的认识,但没有这样的事情。

如果我的计算机中有一个地方可以存储实际的、正确的、经天文调整的日期,那么当我拿起它并向东或向西旅行的那一刻,我的“实际”日期和时间应该已经改变了。

现在,我电脑里的魔法盒怎么会知道呢?

所以,不,没有“实际”日期/时间。

您可以使用两个日期/时间:

1) 用户系统报告的本地。就用户而言,这实际的日期/时间。

2) 参考日期/时间,如 UTC,或预定义时区中的任何当前时间。这与客户报告的日期/时间无关。

当然,您可以做的是尝试找出客户的地理位置,并计算客户的实际日期/时间应该是与祖鲁时间的偏移量。

于 2013-10-30T10:35:42.547 回答