how to get real date (not system date) by c# or c++?

前端 未结 5 783
情歌与酒
情歌与酒 2021-01-13 12:49

Is it possible to get real date (not system date) without any connection to internet? I developed my application by C#. DateTime.Now gets system date but I want to know real

相关标签:
5条回答
  • 2021-01-13 13:25

    Without Internet you are going to need a GPS receiver or Radio clock device.

    You can call upon an NTP server if you can establish some form of Internet connection which should give accurate (atomic) time. C# doesn't have a built in NTP client that I know of but there is one available from:

    http://mftoolkit.codeplex.com/

    Info on NTP can be found here:

    http://en.wikipedia.org/wiki/Network_Time_Protocol

    0 讨论(0)
  • 2021-01-13 13:26

    You can only do this if you know how much your system date varies from the "real date." If you have this delta in a TimeSpan object, you could then do create the "real date" by using DateTime.Now.Add(delta). If you don't have a network connection, you'll have to get the delta some other way, such as a user-entered value. This will be tough though, as the frequency of the system clock on a machine can vary.

    0 讨论(0)
  • 2021-01-13 13:29

    No. In the absence of any external communications, all you've got is the clock in the computer. If you're not going to trust that, you're stuffed.

    Of course, if you're trying to prevent someone from blowing a timed trial licence of software, you could do things like recording the latest UTC time you've ever seen, and becoming suspicious if you see an earlier startup time than the previous startup... especially if you see that repeatedly. That's not the same as getting the real date, of course.

    0 讨论(0)
  • 2021-01-13 13:31

    If the system date is wrong, then your application has to get the correct date from somewhere else. That means and outside resource. It can be over the web, it could be another server in your network, or you could enter it manually. There are no magical solutions.

    0 讨论(0)
  • 2021-01-13 13:36

    Even without the internet, there are other "reliable" external time sources. However, the internet is the easiest and a number of time protocols/servers already exist. These are provided as thoughts, and not necessarily as viable solutions.

    1. NIST atomic clock broadcasts (e.g. how those "atomic watches" work). I am not sure of any commodity hardware for a PC to read these signals. Go befriend an electronics engineer.

    2. GPS. There is plenty of different GPS hardware available to connect to a PC (USB dongles, etc). Even, say, an iPhone. (Modern cell phones will get time synchronization from the network, even without GPS support.)

    3. Your very own atomic clock! Drift should be ignorable ;-)

    Happy ... stuff.

    0 讨论(0)
提交回复
热议问题