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

  • Home
  • SEARCH
  • 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 77829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:53:30+00:00 2026-05-10T20:53:30+00:00

Is there a way to define the timezone for an application in ASP.NET such

  • 0

Is there a way to define the timezone for an application in ASP.NET such that all times read from/compared to current server time are implicitly converted, or do I need to put in conversion statements as each and every DateTime.Now call?

  • 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. 2026-05-10T20:53:31+00:00Added an answer on May 10, 2026 at 8:53 pm

    I am not sure about the latest evolutions of ASP, but this article from 2006 provides an interesting answer:

    The problem is that timezone information is not directly available through the web browser. You could use heuristics to determine the correct time zone or you will have to store the timezone settings for a user based on their selection.

    What follows may not be need with .Net 3.5 and its TimeZoneInfo..ConvertTime method, but still, for completeness sake:

    Once you have the timezone settings you now need to translate the times. You should always store your date/time values in the DB in UTC. This eliminates many conversion issues. If you store the information in UTC then you need only translate from UTC to the user’s local timezone when you display the data to them and you need to convert from their time zone to UTC when you get date/time values from them.

    What makes this more difficult is the fact that the TimeZone class is not all that useful. Fortunately in v2.0 DateTime was updated to support an indicator on whether the time is in UTC or not. You can convert a DateTime to UTC using the DateTime.ToUniversalTime method. Unfortunately however you can’t convert it back.

    The ToLocalTime method uses the local time zone which, when run on the server, uses the server’s time zone which isn’t what you wanted. Even worse however is that you can’t simply create a TimeZone object and use it as that support doesn’t exist.

    Michael Brumm created a nice little class for being able to create and use time zones easily. I personally use a heavily modified version of that code in my own apps and it works nicely. Here are the steps to convert from a DB UTC value to the local user’s time zone.

    1) Get the stored timezone value for the user
    2) Create a SimpleTimeZone class to wrap it (using some mapping scheme that maps a DB value to the underlying Windows registry version)
    3) Use the SimpleTimeZone.ToLocalTime method to convert the DateTime value to the local time.

    For performance reasons you should probably get and initialize the SimpleTimeZone instance and cache it in the Items property for the length of the request so you don’t have to keep creating it.

    For converting from the user’s local timezone to UTC do the reverse:

    1) Get the stored timezone value from the user
    2) Create a SimpleTimeZone class to wrap it
    3) Use SimpleTimeZone.ToUniversalTime method to convert the DateTime to UTC.

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

Sidebar

Related Questions

Is there a simple way to define a breakpoint, in Visual C++ 2005, that
Premise I believe that there is a way to objectively define "Good" and "Bad"
Is there a way to define a program's working directory to be different from
Is there a way to define a configuration XML for Checkstyle in Eclipse that
Is there a way to define aliases so that shell-command can recognize them? shell
Is there a way to define styles for a combination of classes? For example,
Is there a way to define the weekly period I would like to use
Is there some way I can define String[int] to avoid using String.CharAt(int) ?
Is there any syntactical way in jQuery to define multiple CSS attributes without stringing
I wonder if there is a way to set the value of #define in

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.