WorldClock is an application that I was inspired by seeing my dear wife Meenakshi (who still needs to start blogging). was struggling to find something decent for finding out the time in other cities and TimeZones as she works mostly with people in the US while living in London. Though there are some sites which do a decent job, I was intrigued and wanted to see if I could write something quick to help her out and learn for myself. So, here is the result. I call it WorldClock and you can download the code if you feel like or the latest build or check out some screenshots.
The heart of the application is the class TimeZoneInformation and more specifically the Win32 structure TZI (Time Zone Information). Usinig PInvoke.net getting the .NET representation was easy as shown below.
[StructLayout (LayoutKind.Sequential , CharSet=CharSet.Unicode)]
private struct TIME_ZONE_INFORMATION {
[MarshalAs (UnmanagedType.I4)] public Int32 Bias;
[MarshalAs (UnmanagedType.ByValTStr , SizeConst=32)] public
string StandardName;
public SYSTEMTIME StandardDate;
[MarshalAs (UnmanagedType.I4)] public Int32 StandardBias;
[MarshalAs (UnmanagedType.ByValTStr , SizeConst=32)] public
string DaylightName;
public SYSTEMTIME DaylightDate;
[MarshalAs (UnmanagedType.I4)] public Int32 DaylightBias;
}
[StructLayout (LayoutKind.Sequential)]
private struct SYSTEMTIME {
public UInt16 wYear;
public UInt16 wMonth;
public UInt16 wDayOfWeek;
public UInt16 wDay;
public UInt16 wHour;
public UInt16 wMinute;
public UInt16 wSecond;
public UInt16 wMilliseconds;
}
[StructLayout (LayoutKind.Sequential)]
private struct TZI {
public int bias;
public int standardBias;
public int daylightBias;
public SYSTEMTIME standardDate;
public SYSTEMTIME daylightDate;
}
The rest of the code in TimeZoneInformation class is to create a list of all the timezones available in the registry (HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones), converting it to Universal Time (UTC), and then based on that calculate the actual time in the various timezones. I implement the IComparer interface to compare between two instances of TZI.
All the other classes in the application is mainly to support the GUI and the various "features". You can configure how many clocks you want to see and the TimeZones for each and then save that locally. Once you have saved it, everytime the app loads it will automatically load the last saved file. E.g. if you wanted to keep track of time in London, San Francisco, Chicago and New Delhi, then you can setup four clocks and set them to the relevant timezones. Currently each clock shows up in its own tab, down the road this possibly all can be shown on just one tab, but I personally find that there is too much information on that one screen then. When a clock is added, by default it will pick up whatever the system timezone is set to.
Downloading the Code: Feel free to modify the code as long as you give credit to the various sources from where I got portions of the code or inspiration or both.
Downloading the Binaries: I only have the release version of the application. If you are interested in the debug version then contact me and I will email it to you. Also please note this has been tested on WinXP and higher and will not work with Windows 95/98/ME/NT 4. If you are using any of those OS's well as most of them are already at end of life or about to approach I would recommend upgrading *grin*. You will also need .NET runtime. Although this supports both v1.0 and v1.1 of the runtime. I only tested this with v1.1 only.
Screenshots: Keep watching this space, I will be uploading some very soon.
Known Issues: Let me know if you find any bugs or any feature requests. Below is the list of bugs that are there so far.