Quick Objects Documentation Akal Tech Logo
Converting DateTime Values Between Two Time Zones

Glossary Item Box

Time Zones - Tutorial 2:

As you saw in the Tutorial 1 that it is relatively very easy to convert time between UTC and any given time zone. This tutorial shows you another very useful feature that allows you to convert date time directly from one time zone to another time zone. The tutorial uses the same "Form" and controls to display the data and for user selection, thus the code below is only for the portion that shows how to convert date time between two time zones.  Please make sure that you read the Tutorial 1 first before trying this tutorial.

// If the user selected more than one time zone, lets fine the time difference between the two selected rows. Any subsequent selections are ignored.

// The following code is described in the Tutorial 2 of Time Zones Tutorial.

if (this.GridView.SelectedRows.Count > 1)

{

int remoteKey = (int)this.GridView.SelectedRows[1].Cells["Key"].Value;

int localKey = (int)this.GridView.SelectedRows[0].Cells["Key"].Value;

// The GetLocalTimeFromRemoteZone method makes it easy to convert a DateTime value (from remote time zone) to a local time zone.

// Simply passing the DateTime value and the ZoneKey value for the Remote and Local zones will do the trick.

DateTime localDateTime = Akal.QuickObjects.TimeZones.TimeZoneInformation.GetLocalTimeFromRemoteZone(value, remoteKey, localKey);

this.Label_ConvertedTime.Text = "When the time in " + this.GridView.SelectedRows[1].Cells["DisplayName"].Value.ToString() + " is " + value.ToString() + Environment.NewLine + "then the time in " + this.GridView.SelectedRows[0].Cells["DisplayName"].Value.ToString() + " is " + localDateTime.ToString();

}