locked
ASP.NET timezone: how to set the client timezone? RRS feed

  • Question

  • User-551298588 posted

    How do I set the timezone in my asp.net application?


    The problem is that the server is in a different timezone, so everything is registered a few hours earlier than the actual time that I'm using.
    I supposed it was through the CultureInfo, but I can't find anywhere to set it.


    When I am storing the datetime into the database, I am storing UTC/GMT time. While displaying at clients browswer It displaying the UTC/GMT time only, but I need to display the Client Time. Like Add/Remove client offset time (with daylight saving). How Can I convert UTC/GMT time to Client Locale Time? How  can I determine the Client Time Zone? Is there any way to know Client's time zone dynamically in ASP.NET.


    I'm using ASP.NET 1.1 and C#.

    Thursday, January 25, 2007 4:20 AM

Answers

  • User-1683291434 posted

    Hi,

    you could have a simple java script on your login page or on the master page(probably you don;t have a master page since you use .net 1.1 :))

    sth like:

    <script type="text/javascript">
    function getMinutesOffset() {
    var today = new Date();");
    var minDiff = today.getTimezoneOffset();");
    document.aspnetForm.ctl00_ContentCPH_HiddenFieldTimeOffset.value=minDiff;}"
    </script>

    This script detects the user time offset in minutes and assign in to a hidden field;

    You could put it later in the Session object (or could create a cookie).

    So each time you show user some dates , you need to convert them from utc format to the user time simply by adding the timeoffset of the user to the initial date.

    Cheers,

    Yani
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 25, 2007 6:00 AM
  • User113421904 posted

    Hi,

    You might want to have a look at this thread:

    http://forums.asp.net/thread/1535447.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 28, 2007 10:18 PM

All replies

  • User-1683291434 posted

    Hi,

    you could have a simple java script on your login page or on the master page(probably you don;t have a master page since you use .net 1.1 :))

    sth like:

    <script type="text/javascript">
    function getMinutesOffset() {
    var today = new Date();");
    var minDiff = today.getTimezoneOffset();");
    document.aspnetForm.ctl00_ContentCPH_HiddenFieldTimeOffset.value=minDiff;}"
    </script>

    This script detects the user time offset in minutes and assign in to a hidden field;

    You could put it later in the Session object (or could create a cookie).

    So each time you show user some dates , you need to convert them from utc format to the user time simply by adding the timeoffset of the user to the initial date.

    Cheers,

    Yani
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 25, 2007 6:00 AM
  • User113421904 posted

    Hi,

    You might want to have a look at this thread:

    http://forums.asp.net/thread/1535447.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 28, 2007 10:18 PM
  • User-731538705 posted
    As long as al users are in the same time zone as the server... Ahhhhh, no
    Sunday, November 24, 2013 7:42 PM