Managing time zones

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can create a new time zone and add it to the system:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Create new object

        TimeZoneInfo tzi = new TimeZoneInfo();

 

        // Set properties

        tzi.TimeZoneName = "TestTimeZone";

        tzi.TimeZoneDisplayName = "Test time zone";

        tzi.TimeZoneGMT = 2;

        tzi.TimeZoneDaylight = true;

        tzi.TimeZoneRuleStartRule = "MAR|SUN|1|LAST|3|0|1";

        tzi.TimeZoneRuleEndRule = "OCT|SUN|1|LAST|3|0|0";

        tzi.TimeZoneRuleStartIn = TimeZoneInfoProvider.CreateRuleDateTime(tzi.TimeZoneRuleStartRule);

        tzi.TimeZoneRuleEndIn = TimeZoneInfoProvider.CreateRuleDateTime(tzi.TimeZoneRuleEndRule);

 

        // Save to database

        TimeZoneInfoProvider.SetTimeZoneInfo(tzi);

 

The following sample code shows how you can modify the Display name of an existing time zone:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Get time zone object

        TimeZoneInfo tzi = TimeZoneInfoProvider.GetTimeZoneInfo("TestTimeZone");

 

        // If time zone exists

        if (tzi != null)

        {

            // Update property

            tzi.TimeZoneDisplayName += " updated";

 

            // Save to database

            TimeZoneInfoProvider.SetTimeZoneInfo(tzi);

 

        }

 

The following sample code shows how you can delete an existing time zone:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Get time zone object

        TimeZoneInfo tzi = TimeZoneInfoProvider.GetTimeZoneInfo("TestTimeZone");

 

        // If time zone exists

        if (tzi != null)

        {

            // Delete from database

            TimeZoneInfoProvider.DeleteTimeZoneInfo(tzi);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_managing_time_zones.htm