// Save the timezone TimeZoneInfoProvider.SetTimeZoneInfo(newTimezone); }
The following example gets and updates a time zone.
privatebool GetAndUpdateTimezone() {
// Get the timezone TimeZoneInfo updateTimezone = TimeZoneInfoProvider.GetTimeZoneInfo("MyNewTimezone");
if (updateTimezone != null) {
// Update the properties updateTimezone.TimeZoneDisplayName = updateTimezone.TimeZoneDisplayName.ToLower();
// Save the changes TimeZoneInfoProvider.SetTimeZoneInfo(updateTimezone); returntrue; } returnfalse; }
The following example gets and bulk updates time zones.
privatebool GetAndBulkUpdateTimezones() { // Prepare the parameters string where = "TimeZoneName LIKE N'MyNewTimezone%'"; // Get the data DataSet timezones = TimeZoneInfoProvider.GetTimeZones(where, null); if (!DataHelper.DataSourceIsEmpty(timezones)) { // Loop through the individual items foreach (DataRow timezoneDr in timezones.Tables[0].Rows) { // Create object from DataRow TimeZoneInfo modifyTimezone = newTimeZoneInfo(timezoneDr);
// Update the properties modifyTimezone.TimeZoneDisplayName = modifyTimezone.TimeZoneDisplayName.ToUpper();
// Save the changes TimeZoneInfoProvider.SetTimeZoneInfo(modifyTimezone); } returntrue; } returnfalse; }
The following example deletes a time zone.
privatebool DeleteTimezone() {
// Get the timezone TimeZoneInfo deleteTimezone = TimeZoneInfoProvider.GetTimeZoneInfo("MyNewTimezone");
// Delete the timezone TimeZoneInfoProvider.DeleteTimeZoneInfo(deleteTimezone); return (deleteTimezone != null); }
The following example gets the time according to the current user's time zone settings.
privatebool ConvertTime() {
// Get user UserInfo user = UserInfoProvider.GetFullUserInfo(CMSContext.CurrentUser.UserID);
// If user exist if (user != null) {
// Get converted time System.DateTime convertedTime = TimeZoneHelper.ConvertUserDateTime(System.DateTime.Now, user);