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

We have got two method in Sharepoint to get the time. One is ToUniversalTime() an secound is ToLocalTime() But when we are in server and have got a aplication instaled on server which kind data method is better ? If wee set a ToLocalTime it will take a time from server or from local machine loging to our aplication ? Please help.

share|improve this question

this is the difference.

ToUniversalTime does:

return TimeZoneInfo.ConvertTimeToUtc(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);

Instead ToLocalTime does:

  if (this.Kind == DateTimeKind.Local)
    return this;
  bool isDaylightSavings = false;
  bool isAmbiguousLocalDst = false;
  long ticks = this.Ticks + TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
  if (ticks > 3155378975999999999L)
    if (throwOnOverflow)
      throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
      return new DateTime(3155378975999999999L, DateTimeKind.Local);
    if (ticks >= 0L)
      return new DateTime(ticks, DateTimeKind.Local, isAmbiguousLocalDst);
    if (throwOnOverflow)
      throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
      return new DateTime(0L, DateTimeKind.Local);

So seems that the ToLocalTime function get the datetime from the server

share|improve this answer
So we should set all times and data times in ToLocalTime. Not the ToUniversalTime. And If the time changing to the Sammer time it will change if the sammer time changing in Server ? – Grzegorz Z Feb 11 '13 at 12:17
I should change in all playces to the ToLocalTimes ? I afraid it will be in about 200 places where I used ToUniversalTime – Grzegorz Z Feb 11 '13 at 12:21

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.