You might have not faced this problem if you have not work in any project which is very strict in timing. But projects like scheduling and other tasks like users’ subscription with payment must have this features enabled.
With PHP date function you will get the date time of server on which site is located. The only way to get user time is to use JavaScript.
But I suggest you to, if your site have registration required then best way is to ask user while registration as compulsory field. You can list various time zones in register page and save that in database. After this if user login to site then you can set default time zone for that session as per users’ selected time zone. You can set any specific time zone using PHP function date_default_timezone_set. This set the specified time zone for users.
List of supported time zones can be found here.
Basically users’ time zone is goes to client side, so we must use JavaScript for this.
Below is the script to get users’ time zone using PHP and JavaScript.
[cc lang=”javascript”]
[/cc]
But as per my point of view, it’s better to ask to the users if registration is mandatory in your project.
Very good article
I am very thankful to this topic because it really gives up to date information *`;
Very Helpful…Thank You Soo Much! :D A++
Just what I was looking for. Thank you very much