开发者

getting the local time dynamically

How can we know the time of a place from where a person logs in, a particular web application.

I and developing an internal management system for a huge business house in php. The business house has its branches located all over the world. I have to ensure that when an employee logs in to the application he or sh开发者_运维问答e can see the LOCAL TIME. This has to be dynamic. Can anybody help?


As far as I am aware, there is no "magic function" that will allow you to retrieve a user's local time through PHP, but a couple options you might consider are:

  • Using javascript/AJAX to get the local time from the browser and pass it into your application (you could even store it in a database so that you only need to make the call once, if you'd like)
  • Using a geolocation service to look up a user's (approximate) location based on their IP and estimate local time zone from that. If you choose this route, be aware that IP geoloc is pretty much "best guess" technology and can be wildly inaccurate
  • You also might consider simply asking the user what their preferred time zone is. It's not the fanciest method, but it's guaranteed to be right (within a margin of error allowing for user choice)


You can use from date_default_timezone_set php built-In function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜