// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using Microsoft.Win32; namespace E { public class Program { public static int GetUTCOffset1(string target) { RegistryKey tzs = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Time Zones"); foreach(string tzn in tzs.GetSubKeyNames()) { if(tzn.Contains(target) || ((string)tzs.OpenSubKey(tzn).GetValue("Display")).Contains(target)) { return -BitConverter.ToInt32((byte[])(tzs.OpenSubKey(tzn).GetValue("TZI")), 0); } } throw new ArgumentException("Unknown timezone " + target); } public static int GetUTCOffset2(string target) { java.util.TimeZone tz = java.util.TimeZone.getTimeZone(target); return tz.getRawOffset() / 60000; } public static void Main(string[] args) { Console.WriteLine(GetUTCOffset1("Copenhagen")); Console.WriteLine(GetUTCOffset2("EST")); } } }