New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Handling Time Zones

In order to properly handle time zones, RadScheduler uses the TimeZoneInfo object, which comes together with .NET 3.5 . This places some additional overhead, but is essential for solving the following problems:

  • Displaying correct times for the appointments when the clients and/or the server are in different time zones.

  • Correctly evaluating recurrence rules with respect to Daylight Saving Time.

To overcome these problems RadScheduler defines the TimeZoneID property. It uses TimeZoneInfoProvider capable of returning correct LocalToUTC and UTCToLocal information depending on the TimeZone RadScheduler should be operating under. If TimeZoneID is not set initially, the default time zone is (UTC). In addition to this a DataTimeZone field is added to enable eachAppointment to be set in different timezone. The provider and the specific settings in each TimeZone are responsible for all DateTime related calculations.

scheduler timezones

In order to allow selecting individual timezone for each Appointment in the Advanced Form the "EnableCustomTimeZones" property can be set. If it is set to "True"all the appointments inherit the TimeZone of RadScheduler

scheduler timezone advanced Form

If TimeZoneID property is not set the TimeZoneOffset property is applied. In this case during data binding RadScheduler assumes all dates to be UTC.If you use a custom provider or create the Appointment objects programmatically you should take care to convert the date-times to UTC by calling DateTime.ToUniversalTime() or by other appropriate means.

TimeZoneInfo Ids

Timezone IDsTimezone IDsTimezone IDsTimezone IDs
Dateline Standard TimeArgentina Standard TimeIsrael Standard TimeChina Standard Time
UTC-11SA Eastern Standard TimeE. Europe Standard TimeNorth Asia East Standard Time
Samoa Standard TimeGreenland Standard TimeArabic Standard TimeSingapore Standard Time
Hawaiian Standard TimeMontevideo Standard TimeArab Standard TimeW. Australia Standard Time
Alaskan Standard TimeUTC-02Russian Standard TimeTaipei Standard Time
Pacific Standard Time (Mexico)Mid-Atlantic Standard TimeE. Africa Standard TimeUlaanbaatar Standard Time
Pacific Standard TimeAzores Standard TimeIran Standard TimeTokyo Standard Time
US Mountain Standard TimeCape Verde Standard TimeArabian Standard TimeKorea Standard Time
Mountain Standard Time (Mexico)Morocco Standard TimeAzerbaijan Standard TimeYakutsk Standard Time
Mountain Standard TimeUTCMauritius Standard TimeCen. Australia Standard Time
Central America Standard TimeGMT Standard TimeGeorgian Standard TimeAUS Central Standard Time
Central Standard TimeGreenwich Standard TimeCaucasus Standard TimeE. Australia Standard Time
Central Standard Time (Mexico)W. Europe Standard TimeAfghanistan Standard TimeAUS Eastern Standard Time
Canada Central Standard TimeCentral Europe Standard TimeEkaterinburg Standard TimeWest Pacific Standard Time
SA Pacific Standard TimeRomance Standard TimePakistan Standard TimeTasmania Standard Time
Eastern Standard TimeCentral European Standard TimeWest Asia Standard TimeVladivostok Standard Time
US Eastern Standard TimeW. Central Africa Standard TimeIndia Standard TimeMagadan Standard Time
Venezuela Standard TimeNamibia Standard TimeSri Lanka Standard TimeCentral Pacific Standard Time
Paraguay Standard TimeJordan Standard TimeNepal Standard TimeNew Zealand Standard Time
Atlantic Standard TimeGTB Standard TimeCentral Asia Standard TimeUTC+12
Central Brazilian Standard TimeMiddle East Standard TimeBangladesh Standard TimeFiji Standard Time
SA Western Standard TimeEgypt Standard TimeN. Central Asia Standard TimeKamchatka Standard Time
Pacific SA Standard TimeSyria Standard TimeMyanmar Standard TimeTonga Standard Time
Newfoundland Standard TimeSouth Africa Standard TimeSE Asia Standard Time
E. South America Standard TimeFLE Standard TimeNorth Asia Standard Time

Example

This excample is showing how the TimeZoneOffset can be used in custom scenario without TimeZoneID and DataTimeZone properties.

You can allow the user to manually set the preferred time zone or use JavaScript and asynchronous AJAX requests to discover the time zone on the client. This example demonstrates both approaches.

  1. Drag a RadAjaxLoadingPanel from the toolbox onto your Web page. On the body of the loading panel, type the literal "Loading..."

  2. Drag a Panel onto your Web page.

  3. Set its ID property to TimeZonePanel.

  4. Inside the panel, type the literal string "Active Time Zone:"

  5. Following the literal string, drag a Label into the panel. Set its ID to "PleaseWaitLabel" and its text to "[Looking up time zone...]"

  6. Following the label, drag a DropDownList into the panel. Set its ID to "TimeZoneDropDown". Add the following items to the drop-down list:

ASPNET
	     
	
	<asp:DropDownList runat="server" ID="TimeZoneDropDown" AutoPostBack="true">
	 <asp:ListItem Text="GMT -12" Value="-12:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -11" Value="-11:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -10" Value="-10:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -9" Value="-09:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -8" Value="-08:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -7" Value="-07:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -6" Value="-06:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -5" Value="-05:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -4" Value="-04:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -3" Value="-03:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -2" Value="-02:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT -1" Value="-01:00:00"></asp:ListItem>
	<asp:ListItem Text="GMT +0" Value="0:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +1" Value="01:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +2" Value="02:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +3" Value="03:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +4" Value="04:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +5" Value="05:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +6" Value="06:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +7" Value="07:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +8" Value="08:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +9" Value="09:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +10" Value="10:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +11" Value="11:00:00"></asp:ListItem>
	 <asp:ListItem Text="GMT +12" Value="12:00:00"></asp:ListItem>
	</asp:DropDownList>
				
  1. Drag a RadScheduler control from the toolbox onto your Web page. Bind it to a data source of your choice.

  2. Add an event handler to the SelectedIndexChanged event of the drop-down list (TimeZoneDropDown):

C#
	
	    protected void TimeZoneDropDown_SelectedIndexChanged(object sender, EventArgs e)
	    {
	        RadScheduler1.TimeZoneOffset = TimeSpan.Parse(TimeZoneDropDown.SelectedValue);
	    }
	

The drop-down list now allows the user to manually set the time zone of the scheduler.

  1. Drag a RadAjaxManager from the toolbox onto your Web page. In the RadAjaxManager Smart Tag, choose"Configure Ajax Manager". In the property builder that appears, indicate that both the scheduler and the time zone drop-down controls caninitiate requests and thatthe scheduler will be updated by requests. Assign the RadAjaxLoadingPanel as the loading panel when theRadScheduler gets updated.

  2. Give the RadAjaxManager a handler for the AjaxRequest event to update the scheduler and time zone drop-down given an offset:

C#
	
	    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
	    {
	        RadScheduler1.TimeZoneOffset = TimeSpan.FromMinutes(int.Parse(e.Argument));
	        TimeZoneDropDown.SelectedValue = RadScheduler1.TimeZoneOffset.ToString();
	    }
	
  1. Drag a RadCodeBlock component from the toolbox onto your Web page. Switch to the Source view, and add the following script to the code block:
ASPNET
	     
	<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
	 <script type="text/javascript">
	   var syncComplete = false;
	   
	   function SynchronizeClientTimeZoneOffset()
	   {
	     if (!syncComplete)
	     {
	       var ajaxPanel = <%= RadAjaxLoadingPanel1.ClientID %>;
	       var schedulerId = '<%= RadScheduler1.ClientID %>';
	       ajaxPanel.Show(schedulerId);
	     
	       var now = new Date();
	       var offset = now.getTimezoneOffset()
	       InitiateAsyncRequest(-offset);
	     
	       ajaxPanel.Hide(schedulerId);
	     
	       syncComplete = true;
	     }
	   }
	   
	   function InitiateAsyncRequest(argument)
	   {
	      var ajaxManager = <%= RadAjaxManager1.ClientID %>;
	      ajaxManager.AjaxRequest(argument);
	   }
	   
	   Sys.Application.add_load(SynchronizeClientTimeZoneOffset);
	  </script>       
	</telerik:RadCodeBlock> 
	

This defines a global variable, syncComplete, to track when the asynchronous function that looks up and sets the client time zone is complete. It defines two functions:InitiateAsyncRequest, which passes an asynchronous request to the RadAjaxManager with a time zone offset,and SynchronizeClientTimeZoneOffset, which displays the loading panel while it looks up the client time zone and then calls InitiateAxyncRequest to pass that time zone to the AJAX manager so that the appropriate controls are updated. SynchronizeClientTimeZoneOffset is added to handle the loading event of the application.

  1. Finally, in the Page_Load event handler for your Web Page, add code to show or hide the PleaseWaitLabel (note that DataSourceID should be set appropriately for your scheduler):
C#
	
	
	    private void Page_Load(object sender, System.EventArgs e)
	    {
	        if (!IsPostBack)
	        {
	            PleaseWaitLabel.Visible = true;
	            TimeZoneDropDown.Visible = false;
	            RadScheduler1.DataSourceID = "";
	        }
	        else
	        {
	            PleaseWaitLabel.Visible = false;
	            TimeZoneDropDown.Visible = true;
	            RadScheduler1.DataSourceID = "AppointmentsDataSource";
	            RadAjaxLoadingPanel1.InitialDelayTime = 500;
	        }
	    }
	

See Also

In this article
TimeZoneInfo IdsExampleSee Also
Not finding the help you need?
Contact Support