Time zones


List of examples:

Creating a new time zone



// Creates a new time zone object
CMS.Globalization.TimeZoneInfo newTimezone = new CMS.Globalization.TimeZoneInfo();

// Sets the time zone properties
newTimezone.TimeZoneDisplayName = "New time zone";
newTimezone.TimeZoneName = "NewTimezone";
newTimezone.TimeZoneGMT = -12;
newTimezone.TimeZoneDaylight = true;
newTimezone.TimeZoneRuleStartRule = "MAR|SUN|1|LAST|3|0|1";
newTimezone.TimeZoneRuleEndRule = "OCT|SUN|1|LAST|3|0|0";

// Saves the new time zone into the database
CMS.Globalization.TimeZoneInfo.Provider.Set(newTimezone);

> Back to list of examples

Updating a time zone



// Gets the time zone
CMS.Globalization.TimeZoneInfo updateTimezone = CMS.Globalization.TimeZoneInfo.Provider.Get("NewTimezone");
if (updateTimezone != null)
{
    // Updates the time zone properties
    updateTimezone.TimeZoneDisplayName = updateTimezone.TimeZoneDisplayName.ToLower();

    // Saves the changes to the database
    CMS.Globalization.TimeZoneInfo.Provider.Set(updateTimezone);
}

> Back to list of examples

Updating multiple time zones



// Prepares the where condition
string where = "TimeZoneName LIKE N'NewTimezone%'";

// Gets all time zones whose name starts with 'NewTimezone'
var timezones = CMS.Globalization.TimeZoneInfo.Provider.Get().Where(where);         

// Loops through the individual time zones
foreach (CMS.Globalization.TimeZoneInfo timezone in timezones)
{               
    // Updates the time zone's properties
    timezone.TimeZoneDisplayName = timezone.TimeZoneDisplayName.ToUpper();

    // Saves the changes to the database
    CMS.Globalization.TimeZoneInfo.Provider.Set(timezone);
}

> Back to list of examples

Deleting a time zone



// Gets the time zone
CMS.Globalization.TimeZoneInfo deleteTimezone = CMS.Globalization.TimeZoneInfo.Provider.Get("NewTimezone");

if (deleteTimezone != null)
{
    // Deletes the time zone
    CMS.Globalization.TimeZoneInfo.Provider.Delete(deleteTimezone);
}

> Back to list of examples

Converting time to the current user’s time zone



// Gets the current user
UserInfo user = UserInfoProvider.GetFullUserInfo(MembershipContext.AuthenticatedUser.UserID);

// Checks that the user exists
if (user != null)
{
    // Gets the current time converted to the user's time zone
    DateTime convertedTime = TimeZoneHelper.ConvertToUserDateTime(DateTime.Now, user);
}

> Back to list of examples