How to take care of different timezones in RemoteApp

I have a windows applications which are deployed as remoteapp. I'm trying to generate a timestamp using C# DateTime.Now. I'm interested to know, how the timestamp will be generated, in case of user who is using the application from a place having different timezone than that of server which is hosting the application. Will it be the server specific or the user machine specific. If it is according to server timezone, is there any way to make it user machine specific?

Jon Skeet

I'm trying to generate a timestamp using C# DateTime.Now.

It's strongly recommend against doing that. That will use the time zone of the system where the code is running. It's just not suitable for a timestamp. In particular:

  • Unless you also record the time zone, you won't know when the event actually occurred in any particularly meaningful way, including comparing one timestamp with another that might have been captured in a different time zone
  • You'll find that timestamps can go backwards in time due to time zone transitions

Instead, use UTC for all timestamps - so DateTime.UtcNow - and make sure that everywhere that uses those timestamps knows they're in UTC.

Even when using UTC, if you're using DateTime.UtcNow the timestamps will be based on the system clock, so if they're generated on multiple machines that might have system clocks that aren't synchronized with each other, your timestamps won't give a definitive ordering... but you'll be in a lot better position than just using the system local time zone.


See more on this question at Stackoverflow