Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:26:41+00:00 2026-05-30T12:26:41+00:00

Update – the problem didn’t lie within the extension method As it turned out,

  • 0

Update – the problem didn’t lie within the extension method

As it turned out, there was no actual problem with my extension method. When I feed it with a DateTime straight from the webserver like so DateTime.UtcNow.ToUserLocalTime() I realized that the method was actually producing the correct result. The problem was instead that I accidentally called it twice on the DateTimes that were displayed incorrectly – first in the controller and then again in the view. A really stupid mistake, realized after beating my head against the wall for hours. From now on it is called from the controller only.

I have a problem with a time zone conversion in an ASP.Net MVC3 application running in Azure. When I run the application locally, everything is working just fine, however when I run the exact same code in Azure, it ends up +1 hour off.

I have created an extension method for DateTime that I use to convert the DateTime according to the time zone chosen by the user. All DateTimes are stored in UTC.

public static DateTime ToUserLocalTime(this DateTime date)
{
    date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
    if (!string.IsNullOrEmpty(SecurityContext.CurrentUser.TimeZone))
    {
        var timezone = SecurityContext.CurrentUser.TimeZone;
        var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezone);
        return TimeZoneInfo.ConvertTime(date, timeZoneInfo);
    }

    return date;
}

SecurityContext.CurrentUser.TimeZone is a string-representation of the time zone, in my case W. Europe Standard Time.

When I get the DateTime 2011-12-02 13:46:22 from my local SQL-database and run it through my ToUserLocalTime method converting it to W. Europe Standard Time in my local environment I get 2011-12-02 14:46:22 which is correct. However when I run the exact same code in Azure, reading from my SQL-Azure db, which contains the exact same DateTime and chosen time zone I get 2011-12-02 15:46:22. This baffles me, why does it end up one hour off?

I really don’t know how to debug this, since I cannot reproduce it locally. Is there a way to debug this in the Azure role, so that I can see what is really going on in the code? Something like the debugger in Visual Studio?

I tried to enable IntelliTrace when I publish the application, but when I did the application wouldn’t start, complaining about a connection-error when connecting to the Azure-SQL db. I have no experience of IntelliTrace, would the generated logs be able to tell me anything about what is going on here? Would it be worth spending time getting InteliTrace to work in this case?

Any ideas on what might be wrong here, or how to debug it would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:26:43+00:00Added an answer on May 30, 2026 at 12:26 pm

    What about using

    return TimeZoneInfo.ConvertTimeFromUTCTime(date, timeZoneInfo);
    

    instead of

    return TimeZoneInfo.ConvertTime(date, timeZoneInfo);
    

    Reference: http://social.msdn.microsoft.com/Forums/en-AU/windowsazuredevelopment/thread/04be9d07-fcdb-4bf2-b380-57c062382409

    You could then remove the line date = DateTime.SpecifyKind(date, DateTimeKind.Utc);, assuming that your date always has the Unspecified kind

    OR

    Or could it be Daylight Saving messing things up? See http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/92696af4-5169-4015-90eb-79da3c5136c2/

    To test this, try going the page that changes your timezone, by clicking on your computer clock and “Change date and time settings. Then uncheck/check the Automatically adjust time for Daylight Saving.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add
UPDATE: In trying to replicate this problem one more time to answer your questions
[Update] Solved the Problem by generating a new web.config. Possible error was the second
UPDATE : I updated the classes to look more like my actual model. When
UPDATE This is an old question for an old version of Xcode. It turned
Update 2: thanks again to @deepak-azad, I managed to solve my problem : here
UPDATE maybe changing the Bitmap size in the new Activity may fix the problem
UPDATE: This problem goes away when I deploy as an exploded EAR i.e. by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.