Reputation: 2484
I think it has something to do with PHP Timezones. My current date and time is 10:51 pm , and 7/15/2013 . (I am on windows and my bottom right is showing it :) )
I use the following php code
<?php
echo date("d/m/y : H:i:s", time());
?>
And the browser displayed: 15/07/13 : 19:06:15
(about 3 hours and 45 minutes early).
First Question: Why does it happen?
Second Question: If it is because PHP's default timezone is something else (mine is GMT 5:45), how can i edit the php's conf (or whatever) so that time() returns time for my timezone?
Upvotes: 0
Views: 58
Reputation: 30313
Remember that PHP is server-side. The time it returns is bound to the server the code is running on. The php.ini setting is date.timezone
. But you can use date_default_timezone_set
to override the timezone specifically for your script. If you want to get the time in the timezone of the client, however, you have to use a client-side method like Javascript.
Upvotes: 2
Reputation: 7566
You can either set the time zone in your php.ini file or you can do it in the code:
<?php
date_default_timezone_set('America/Los_Angeles');
?>
http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone http://php.net/manual/en/function.date-default-timezone-set.php http://www.php.net/manual/en/timezones.php
Also date_default_timezone_get()
will show you what timezone you currently have set.
Upvotes: 3