Skip to main content

SharePoint online - Update timezone for a sitecollection via CSOM

Here is a snippet to update timezone for a site-collection via CSOM



            Web web = clientContext.Web;
            RegionalSettings webRegionalSettings = web.RegionalSettings;
            clientContext.Load(web);
            clientContext.Load(webRegionalSettings); 
            Microsoft.SharePoint.Client.TimeZone currentTimeZone = webRegionalSettings.TimeZone;
            clientContext.Load(currentTimeZone); 
            clientContext.ExecuteQuery();

            //Get the current site TimeZone  
            ConsoleLogger.LogMessage(LogLevel.Verbose, "Current TimeZone: " + currentTimeZone.Id + " - " + currentTimeZone.Description);

            //Get web timezones
            TimeZoneCollection webTimeZones = webRegionalSettings.TimeZones;
            clientContext.Load(webTimeZones);
            clientContext.ExecuteQuery();

            // 76 (UTC+10:00) Canberra, Melbourne, Sydney
            Microsoft.SharePoint.Client.TimeZone newTimeZone = webTimeZones.GetById(76);
            webRegionalSettings.TimeZone = newTimeZone;
            webRegionalSettings.Update(); 
            clientContext.ExecuteQuery();

Additionally, adding a loop gives me a list of all the SharePoint online timezones
            foreach (Microsoft.SharePoint.Client.TimeZone timezone in webTimeZones)
            {
                ConsoleLogger.LogMessage(LogLevel.Verbose, String.Format("Id : {0} , Description : {1} ", timezone.Id, timezone.Description));

            }

The output looks like :
Id : 39 , Description : (UTC-12:00) International Date Line West
Id : 95 , Description : (UTC-11:00) Coordinated Universal Time-11
Id : 15 , Description : (UTC-10:00) Hawaii
Id : 14 , Description : (UTC-09:00) Alaska
Id : 78 , Description : (UTC-08:00) Baja California
Id : 13 , Description : (UTC-08:00) Pacific Time (US and Canada)
Id : 38 , Description : (UTC-07:00) Arizona
Id : 77 , Description : (UTC-07:00) Chihuahua, La Paz, Mazatlan
Id : 12 , Description : (UTC-07:00) Mountain Time (US and Canada)
Id : 55 , Description : (UTC-06:00) Central America
Id : 11 , Description : (UTC-06:00) Central Time (US and Canada)
Id : 37 , Description : (UTC-06:00) Guadalajara, Mexico City, Monterrey
Id : 36 , Description : (UTC-06:00) Saskatchewan
Id : 35 , Description : (UTC-05:00) Bogota, Lima, Quito
Id : 10 , Description : (UTC-05:00) Eastern Time (US and Canada)
Id : 34 , Description : (UTC-05:00) Indiana (East)
Id : 88 , Description : (UTC-04:30) Caracas
Id : 91 , Description : (UTC-04:00) Asuncion
Id : 9 , Description : (UTC-04:00) Atlantic Time (Canada)
Id : 81 , Description : (UTC-04:00) Cuiaba
Id : 33 , Description : (UTC-04:00) Georgetown, La Paz, Manaus, San Juan
Id : 65 , Description : (UTC-04:00) Santiago
Id : 28 , Description : (UTC-03:30) Newfoundland
Id : 8 , Description : (UTC-03:00) Brasilia
Id : 85 , Description : (UTC-03:00) Buenos Aires
Id : 32 , Description : (UTC-03:00) Cayenne, Fortaleza
Id : 60 , Description : (UTC-03:00) Greenland
Id : 90 , Description : (UTC-03:00) Montevideo
Id : 103 , Description : (UTC-03:00) Salvador
Id : 96 , Description : (UTC-02:00) Coordinated Universal Time-02
Id : 30 , Description : (UTC-02:00) Mid-Atlantic
Id : 29 , Description : (UTC-01:00) Azores
Id : 53 , Description : (UTC-01:00) Cabo Verde
Id : 86 , Description : (UTC) Casablanca
Id : 93 , Description : (UTC) Coordinated Universal Time
Id : 2 , Description : (UTC) Dublin, Edinburgh, Lisbon, London
Id : 31 , Description : (UTC) Monrovia, Reykjavik
Id : 4 , Description : (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
Id : 6 , Description : (UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
Id : 3 , Description : (UTC+01:00) Brussels, Copenhagen, Madrid, Paris
Id : 57 , Description : (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb
Id : 69 , Description : (UTC+01:00) West Central Africa
Id : 83 , Description : (UTC+01:00) Windhoek
Id : 79 , Description : (UTC+02:00) Amman
Id : 5 , Description : (UTC+02:00) Athens, Bucharest, Istanbul
Id : 80 , Description : (UTC+02:00) Beirut
Id : 49 , Description : (UTC+02:00) Cairo
Id : 98 , Description : (UTC+02:00) Damascus
Id : 50 , Description : (UTC+02:00) Harare, Pretoria
Id : 59 , Description : (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
Id : 101 , Description : (UTC+02:00) Istanbul
Id : 27 , Description : (UTC+02:00) Jerusalem
Id : 7 , Description : (UTC+02:00) Minsk (old)
Id : 104 , Description : (UTC+02:00) E. Europe
Id : 100 , Description : (UTC+02:00) Kaliningrad (RTZ 1)
Id : 26 , Description : (UTC+03:00) Baghdad
Id : 74 , Description : (UTC+03:00) Kuwait, Riyadh
Id : 109 , Description : (UTC+03:00) Minsk
Id : 51 , Description : (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2)
Id : 56 , Description : (UTC+03:00) Nairobi
Id : 25 , Description : (UTC+03:30) Tehran
Id : 24 , Description : (UTC+04:00) Abu Dhabi, Muscat
Id : 54 , Description : (UTC+04:00) Baku
Id : 106 , Description : (UTC+04:00) Izhevsk, Samara (RTZ 3)
Id : 89 , Description : (UTC+04:00) Port Louis
Id : 82 , Description : (UTC+04:00) Tbilisi
Id : 84 , Description : (UTC+04:00) Yerevan
Id : 48 , Description : (UTC+04:30) Kabul
Id : 58 , Description : (UTC+05:00) Ekaterinburg (RTZ 4)
Id : 87 , Description : (UTC+05:00) Islamabad, Karachi
Id : 47 , Description : (UTC+05:00) Tashkent
Id : 23 , Description : (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
Id : 66 , Description : (UTC+05:30) Sri Jayawardenepura
Id : 62 , Description : (UTC+05:45) Kathmandu
Id : 71 , Description : (UTC+06:00) Astana
Id : 102 , Description : (UTC+06:00) Dhaka
Id : 46 , Description : (UTC+06:00) Novosibirsk (RTZ 5)
Id : 61 , Description : (UTC+06:30) Yangon (Rangoon)
Id : 22 , Description : (UTC+07:00) Bangkok, Hanoi, Jakarta
Id : 64 , Description : (UTC+07:00) Krasnoyarsk (RTZ 6)
Id : 45 , Description : (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi
Id : 63 , Description : (UTC+08:00) Irkutsk (RTZ 7)
Id : 21 , Description : (UTC+08:00) Kuala Lumpur, Singapore
Id : 73 , Description : (UTC+08:00) Perth
Id : 75 , Description : (UTC+08:00) Taipei
Id : 94 , Description : (UTC+08:00) Ulaanbaatar
Id : 20 , Description : (UTC+09:00) Osaka, Sapporo, Tokyo
Id : 72 , Description : (UTC+09:00) Seoul
Id : 70 , Description : (UTC+09:00) Yakutsk (RTZ 8)
Id : 19 , Description : (UTC+09:30) Adelaide
Id : 44 , Description : (UTC+09:30) Darwin
Id : 18 , Description : (UTC+10:00) Brisbane
Id : 76 , Description : (UTC+10:00) Canberra, Melbourne, Sydney
Id : 43 , Description : (UTC+10:00) Guam, Port Moresby
Id : 42 , Description : (UTC+10:00) Hobart
Id : 99 , Description : (UTC+10:00) Magadan
Id : 68 , Description : (UTC+10:00) Vladivostok, Magadan (RTZ 9)
Id : 107 , Description : (UTC+11:00) Chokurdakh (RTZ 10)
Id : 41 , Description : (UTC+11:00) Solomon Is., New Caledonia
Id : 108 , Description : (UTC+12:00) Anadyr, Petropavlovsk-Kamchatsky (RTZ 11)
Id : 17 , Description : (UTC+12:00) Auckland, Wellington
Id : 97 , Description : (UTC+12:00) Coordinated Universal Time+12
Id : 40 , Description : (UTC+12:00) Fiji
Id : 92 , Description : (UTC+12:00) Petropavlovsk-Kamchatsky - Old
Id : 67 , Description : (UTC+13:00) Nuku'alofa
Id : 16 , Description : (UTC+13:00) Samoa

Comments