C# event to detect Daylight Saving or even manual time change

后端 未结 3 1991
广开言路
广开言路 2020-12-07 03:45

I run an application as a service on a server and then I have multiple clients connect to that service. I display the exact server time on each of the client Window form ap

3条回答
  •  借酒劲吻你
    2020-12-07 04:29

    Well I would strongly suggest not relying on the local time to start with. Use the UTC time of the server, and then if you need to convert that to the local time you can do that wherever you want to, if you know its time zone.

    Detecting a manual time change without a useful event is slightly tougher, but could you just run a timer which executes every (say) 30 seconds and checks whether the UTC time isn't "UTC time at least timer tick + 30 seconds" with some amount of tolerance?

    You don't need to run it terribly often, so it's not like it's going to be a huge waste of resources. You could always hide this behind an API which can be replaced with a more efficient one if you ever do find a better answer :)

提交回复
热议问题