How to Get the Time zone settings in Office 365 using CSOM?

In Office 365, we can  get the Time zone settings for a site collection under Regional Settings. You always provide time zone while creating a site Collection, In this article, I’m providing you the sample code to get the Time Zone Settings using Client Side object model.

// Get access to source site
using (ClientContext context = new ClientContext(“https://my.sharepoint.com/sites/”))
{
SecureString passWord = new SecureString();

foreach (char c in “*****”.ToCharArray()) passWord.AppendChar(c);

context.Credentials = new SharePointOnlineCredentials(“yourID@my.onmicrosoft.com”, passWord);

// Actual code for Getting Client Context
Web web = context.Web;
context.Load(web,
webSite => webSite.Title);

context.ExecuteQuery();
RegionalSettings regSettings = web.RegionalSettings;
context.Load(web);
context.Load(regSettings);

//To get regional settings properties
Microsoft.SharePoint.Client.TimeZone currentTimeZone = regSettings.TimeZone;
context.Load(currentTimeZone);

//To get the TimeZone propeties for the current web region settings
context.ExecuteQuery();

}

Please read my next article on how to set the time zone using CSOM.

Happy Share Pointing 🙂 Hope it helps you guys!!

Leave a Reply

Your email address will not be published.