Search code examples
c#.nettimezoneutc

Is the Time Zone 'UTC' available on every windows system?


I work on a large project where we need to store the user's time zone information. We are doing so by persisting the 'Id' of the System.TimeZone object as a string (yeah, the id really is a string..) to the database.

Additionally, there is a base seed script that adds an admin user to the database to provide a first user to set things up.

Now my problem is that I set the time zone id in that script to Central European Standard Time, which then doesn't seem to be available on the customers server..

Is it a good idea to store UTC as the time zone for the admin? Is the time zone information 'UTC' always available on a windows system? (like Windows Server 2012 R2)


Solution

  • A few things:

    • I think you meant the System.TimeZoneInfo class, because the System.TimeZone class does not have an Id property. That's fine, because you should consider System.TimeZone deprecated anyway.

    • The time zones exposed by the TimeZoneInfo class are the standard Windows operating system time zones, found in the registry under the following key:

      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
      
    • Yes, the "UTC" time zone is available on every Windows system, and so should the "Central European Standard Time" time zone. If they are not available on the customer's Windows computers, then their Windows registry has been manipulated manually, or become corrupted. It can be restored by taking a backup of the registry key shown above from another computer and copying it in place, or by simply installing the latest updated listed here. (The June 2016 update, as of writing this.)

    • Storing the Id of the time zone is perfectly fine. Yes, it is a string. That's how time zone identifiers work. You should read the time zone tag wiki for better understanding.

    • Nobody can answer which time zone your admin should use. That's entirely specific to your application. Perhaps there could be multiple admins for different parts of the world, or perhaps admins might need to see some data in context using some other time zone. There's no one right approach here. You may be able to get some ideas from reading Daylight saving time and time zone best practices.

    • Time zone issues can be tricky, and there are many good questions here on StackOverflow you should research before going much further. You might also want to read the many articles on Wikipedia about time zones in general or in particular locations, or look for training materials such as videos on Pluralsight.