SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why when I Adding a Data Veriable I must correct them by adding some hours to them. When I using ToUniversalTime().AddHours(2.0) i must add a two hours, and if I using ToLocalTime().AddHours(-1.0) I must minus One Hour.

share|improve this question
up vote 4 down vote accepted

Maybe you can use something like this:

using (SPSite site = new SPSite("siteurl"))
     using (SPWeb web = site.OpenWeb())
          SPUser user = web.CurrentUser;
          SPRegionalSettings settings = user.RegionalSettings;
          if(settings != null){
              SPTimeZone zone = user.RegionalSettings.TimeZone;
              DateTime UTCTime = zone.LocalTimeToUTC(DateTime.Now);//Convert to UTC
              DateTime LocalTime = zone.UTCToLocalTime(UTCTime);//Convert to local time

So to convert a value from the user's timezone, convert it to UTC with zone.LocalTimeToUTC and to convert it back, use UTCToLocalTime.

Warning: I guess this will take the regional settings of the user in SHAREPOINT, not from your computer... So if you move to another timearea, you'll still convert to regionalsettings in the previous region...

Also, I don't know how this will work with winter or summer-time...

share|improve this answer

Timezones vary between eachother.

share|improve this answer
Yes I know It, but it isnt Any C# class without timezones ? – Grzegorz Z Oct 31 '12 at 12:40
I must say I failed to understand your question. Can you be more specific? – Rafał Saltarski Oct 31 '12 at 12:44
AFAIK DateTime defaults to Coordinated Universal Time (UTC). Normally, when you use .ToLocal() it should correctly account for daylight savings and whatnot, and it should return the correct date and time. If that's not working, I guess maybe your system doesn't have the correct timezone set? check Site Settings -> Regional Settings – Spongeroberto Squarepantalones Oct 31 '12 at 12:53
I asking about the method how I should get corect timezone, without any Adding, or decrease. Is there any methods without in C# for dete for only days, or with hours only 00:00 – Grzegorz Z Oct 31 '12 at 13:01
When you create a datetime object, try explicitly mentioning the timezone by using DateTimeKind.Local: DateTime mydate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Local); – Spongeroberto Squarepantalones Oct 31 '12 at 13:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.