0

I have developed an application in C# which uses the time of the system. My problem is that if someone changes the time of the system, it affects the application also. The application would then show data of that changed time and not the current time.

How do i avoid this? Is there any other way to get a single universal time?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Mohnish
  • 71
  • 9
  • 4
    use a web service or a central server for the time. – Daniel A. White Mar 16 '12 at 14:47
  • Of course, even accessing a time server wouldn't be _completely_ "unchangeable." If the user really wants to, they can intercept the request and return a custom response :) – David Mar 16 '12 at 14:49
  • As @Daniel said you need to use NTP server as outlined [here](http://stackoverflow.com/a/516812/884410) – Raj Ranjhan Mar 16 '12 at 14:50
  • If you have a need to enforce reliable time on the client, use group policy to deny the Change the System Time right and make sure that the Windows Time Service is configured via group policy as well. Otherwise, don't use the client for time. Do your time-related operations on the application server or database server. – JamieSee Mar 16 '12 at 15:33
  • Does it need to be clock time, or do you just need to measure intervals? Have you looked at GetTickCount? – Harry Johnston Mar 17 '12 at 05:41

2 Answers2

3

You can use NTP to ask to an authoritative time server what time it is, for example. If you google for NTP client C# you'll find plenty of examples.

xanatos
  • 109,618
  • 12
  • 197
  • 280
0

If time is so critical, keep anything that is dependent on the time isolated on the server. Move the actual processing to the server, and just display the result on the client.

dotnetengineer
  • 1,254
  • 1
  • 9
  • 18