Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

asp.net - Can You Determine Timezone from Request Variables?

Is there a way to do your timezone offsets on the server side, by reading something in the request over http, instead of sending everything to the client and letting it deal with it?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is more complicated but I've had to resort to this scenario before because machine and user profile settings sometimes don't match your visitor's preferences. For example, a UK visitor accessing your site temporarily from an Australian server.

  1. Use a geolocation service (e.g MaxMind.com) as suggested by @balabaster, to get the zone matching their IP (Global.Session_Start is best). This is a good match for local ISPs, but not so good for AOL. Store the offset from this in a session cookie.

  2. Or use JavaScript to get the time zone offset as part of a form submission/redirect when the user enters the site. This is the browser's current offset, but not necessarily the visitor's preferred zone. Use this value as a default; store in another session cookie.

    
    <script type="text/javascript" language="JavaScript">
    var offset = new Date();
    document.write('<input type="hidden" id="clientTzOffset" name="clientTzOffset" value="' + offset.getTimezoneOffset() + '"/>');
    </script>
    
  3. Allow the visitor to update the zone via a persistent cookie (for anonymous users) and a field in their account profile (if authenticated).

The persistent value #3 from overrides the session values. You can also store the same persistent cookie for authenticated users for displaying times before they login.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...