动态获取当地时间

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 she can see the LOCAL TIME. This has to be dynamic. Can anybody help?

You can use from date_default_timezone_set php built-In function

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)