Determine a user's timezone

前端 未结 25 3333
刺人心
刺人心 2020-11-21 07:12

Is there a standard way for a web server to be able to determine a user\'s timezone within a web page?

Perhaps from an HTTP header or part of the user-agent

25条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-21 07:19

    Here is an article (with source code) that explains how to determine and use localized time in an ASP.NET (VB.NET, C#) application:

    It's About Time

    In short, the described approach relies on the JavaScript getTimezoneOffset function, which returns the value that is saved in the session cookie and used by code-behind to adjust time values between GMT and local time. The nice thing is that the user does not need to specify the time zone (the code does it automatically). There is more involved (this is why I link to the article), but provided code makes it really easy to use. I suspect that you can convert the logic to PHP and other languages (as long as you understand ASP.NET).

提交回复
热议问题