Reputation: 267
I'm just wondering how the php function date()
works? Like how does it determine time and date to return?
For example if my php code on a page looked something like this:
<?php
echo date("h:i:sa");
?>
It will simply echo out (for example) 11:18:24am
, but let's say a site visitor from another country visits page, will the time returned be appropriate for their timezone? Hopefully this question makes sense, i only ask because I couldn't find anything on Google when searching how php date()
function works.
Upvotes: 1
Views: 310
Reputation: 61
I had the same problem but here is how i solved it. In the php.ini the timezone is static and set according to the server but you can override this by using date_default_time_zone function. for example you can create a script that tests a visitor location then loads parameters to date_default_timezone_set("continent/city"); according to your visitor location. i hope this works
Upvotes: 1
Reputation: 34003
The date method is documented here: https://secure.php.net/manual/function.date.php
As php scripts are executed on server side, it uses the current date/time of the server, formats and returns it. - There is no conversions for the timezone of visitors of your website. If you need localized times, you need to change the timezone manually.
Upvotes: 2