I’d like to change the default time zone of a .NET CLR without using the registry or changing my OS time zone. Is there a way?
EDIT: It looks like the .NET CLR just doesn’t support having a default time zone different than the OS’s (unlike the JVM).
In other words I’d like this statement to return something other than my OS’s time zone:
TimeZoneInfo timeZoneInfo = TimeZoneInfo.Local;
Console.Out.WriteLine("timeZoneInfo = {0}", timeZoneInfo);
The reason I’d like to do this is to run a .NET GUI with the time zone of my users (London) rather than the time zone of my machine (Chicago).
For example, you can change a Java runtime’s time zone by adding to the commandline:
-Duser.timezone="Europe/Berlin"
So, for example, if you want DateTime.Now to return a different time zone, you can’t without changing all the references to DateTime.Now to something else, which is what I was hoping to avoid in the first place.
You are asking about getting a different result for the time zone setting, but I am assuming in the end you are interested in getting the time returned in another time zone by default.
The .NET framework supports UTC, local, and also a generic time value without a sense of time zone. See the DateTimeKind enumeration.
When dealing with time values I normally use UTC for everything internally and convert to a specific zone when interacting with the user.
So, to answer your question the only way I know to get a local time returned in another time zone is to change the time zone of the machine.
That begin said, to get your desired effect you could write a utility class that gets the time in UTC then use a configuration parameter to store an offset to apply before returning it.