I'm trying to troubleshoot and solve this problem:
the server I'm working on (php 5.2.9 on Linux), has the correct local time (America/Buenos_Aires):
user#server [/home/site/public_html]$ date
Mon Nov 1 17:11:14 ART 2010
php.ini is set with date.timezone = "America/Buenos_Aires"
I also tried to set the timezone directly in the script with
<?php
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT|E_NOTICE);
//date_default_timezone_set("America/Buenos_Aires");
//echo date_default_timezone_get(), "<br>";
echo "ini: ", ini_get('date.timezone'), "<br>";
$now = date("H:i:s T I");
$nowdate = date("Y-m-d");
echo $nowdate." ".$now;
?>
but to no avail, the result is
ini: America/Buenos_Aires
2010-11-01 18:11:14 ARST 1
when it should read 17:11 (It's consistently one hour ahead). All I've found here and on the web pointed to
date_default_timezone_set (which I tried)
setting date.timezone in php.ini (which it is set)
confusing server time with client time (which I'm not).
Any ideas?
EDIT:
As suggested, I checked and as you can see in the code, PHP thinks it should be applying DST, and Argentina decided to not apply it this year. Any option besides waiting for a patch?
EDIT 2:
I tried dumping the timezones transition as suggested. I got the following:
The timezone America/Buenos_Aires switches to standard time on 20 Mar 2011 # 02:00.
The new GMT offset will be: -10800 (ART)
There was a question a few days back that suggested that PHP hasn't yet got wind of the fact that Argentina got rid of DST only this year. It seems like this decision hasn't made it into the code base yet. (But it was not confirmed, so it's not 100% clear whether this was it.)
Maybe try dumping your time zones the same way to see whether that applies to your PHP version, too.
Update: This indeed seems to be the problem. The best solution I can think of is to use an offset in the time zone, e.g. Etc/GMT-3
Somebody should file a bug with bugs.php.net, there doesn't seem to be one for this.
Related
I have the behavior which is cofusing me:
1. I got rom request some string date "02.07.2014".
2. Trying to convert it to timestamp
strtotime($search->date_from)
it returns me 1404244800. Assumig that my bug is here, I'm trying to check what I get on this url http://www.onlineconversion.com/unix_time.htm and found the Tue, 01 Jul 2014 20:00:00 GMT
It's almost what I need , excluding that 4 hours are lost: it's very bad for me and unexpected.
On top of php script, put
date_default_timezone_set("YourTimeZone");
YourTimeZone can be one of this:
Timezone
The strtotime function relies on the system timezone, unless you set it otherwise.
You can set the timezone using date_default_timezone_set, example:
date_default_timezone_set("America/Phoenix");
strtotime(...);
Also, see the timezone reference
Use this link instead and it will determine your LOCAL time. http://www.epochconverter.com
The 4 hours that you are losing is most-likely due to the fact that you do not have your timezone set. You can either do this in the php.ini file or in your .php file.
In your .php file do this:
date_default_timezone_set("America/New_York"); // if you live in USA on east coast
// For a list of possible arguments, go here: http://php.net/manual/en/timezones.php
Hope this helps.
in the php.ini I defined the timezone to Europe/Athens. Everything was just fine until last sunday, when the time chanegd to WINTER TIME. The time went back in 1 hour.
The problem is, that in my website - it's still like summer time, didn't go back in 1 hour... I checked it in other website and it's ok there - http://www.timeanddate.com/worldclock/city.html?n=26
To make sure, I added this line in the top of the page:
ini_set('date.timezone', 'Europe/Athens');
But it dind't help...
What heppent? How can I fix it?
I think this will help you.
date_default_timezone_set('Europe/Athens');
If you just set the default time in the start of your function or program the date is format in the country you want.
<?php
date_default_timezone_set('Europe/Athens') ;
echo "the date is:". date("d/m/Y")."<br/>";
echo "the time is:". date("h:i:s");
?>
Just two little hints:
Please check if the output of following code returns your timezone:
$date = new DateTime();
$tz = $date->getTimezone();
echo $tz->getName();
Which function or language do you use to display the time on your website? Perhaps javascript? Then the time comes from the client system.
You might consider updating your PHP time zone database. You can find the latest version here.
However, I checked through the database and it looks like Europe/Athens has been in sync with EU since 1981, which has used the Last Sunday in October since 1996. So even if you have a very old database I can't imagine that it would be incorrect for recent dates.
I know this is probably a question for ServerFault but I am having difficulty logging in.
I have an Ubuntu instance in the cloud running Nginx + PHP5-fpm.
I have set the timezone in php.ini to Asia/Singapore and verified it is set in phpinfo().
I have set the OS timezone using dpkg-reconfigure tzdata as well.
For some time, I've been having trouble with wrong dates set in my application. I initially thought this might be something I did in my PHP setup, so in my bootstrap script, I included:
date_default_timezone_set('Asia/Singapore');
Tried installing timezonedb via PECL as suggested in this post:
Setting default timezone does not work despite timezone being valid
A user set date set on a webform still gets translated to "yesterday" when processed. I have tried both date() & gmdate() in PHP with the same results.
Edit
A little more information in case.
User selects a date with jQuery DatePicker
On form submission, I send the timestamp back to the server for PHP to process & store. I divide the timestamp by 1000 in PHP before storing.
<?php $timestamp = (int) $_POST['birthday'] / 1000
// this is received from a form.
Upon echoing the date & timestamp,
<?php echo date('dS F Y', (int) $timestamp);
// when rendering to HTML...
// computes to 13th April 1981
//JS
new Date(data.timestamp * 1e3).toString()
// the exact same timestamp from earlier but received from server.
// computes to Tue Apr 14 1981 23:30:00 GMT+0730 (SGT)
Any ideas?
Your clock is assumed to be in UTC/GMT, but the "humanising"/ conversion to a string adds the time zone offset. The HTTP header being in GMT will be on the original value. This is generally how Unix clocks work, it makes global traffic routing possible.
<?php
# my locale is configured for London
var_dump(time(), date('Y-m-d H:i:s'));
date_default_timezone_set('Asia/Singapore');
var_dump(time(), date('Y-m-d H:i:s')); # MySQL, locale
var_dump(time(), date('r')); # RFC 2822
var_dump(time(), date('c')); # ISO 8601
Your server is reporting the correct time in UTC.
To fix, could you emit that header inside the PHP? This will override the first value...
header("Date: ".date('r', time()+8*60*60));
Edit
As you changed the question, more text response...
I think its necessary to confirm all the date-as-int operations are done with UTC/GMT time.
If your user in in Singapore the time will be sent to the server in +8h offset. Are you transmitting as text or an int? All of the jQuery dates I have used return a string.
If you unpack via strtotime(), it corrects the time offset.
The /1000 should have no computation significance, 8h = (60*60*8)s = 28800s which is >1000.
What does your client say for the timezone ~ gettimezoneoffset
It looks like one of the convert-to-int operations didn't remove the timezone offset.
There was a bug listed and patched in Ubuntu launchpad. timestamps are working after updating PHP. An excerpt of the bug:
[Impact]
A regression of timezone handling between Precise and Quantal means that PHP scripts that depend on the system timezone now use UTC instead. This breaks arbitrary PHP scripts - eg. cactus stops working as expected.
Not affected: 5.3.10-1ubuntu3.4 (Precise)
Affected: 5.4.6-1ubuntu1 (Quantal)
Not affected: 5.4.4-7 (sid)
Workaround: edit /etc/php5/*/php.ini, uncomment the "date.timezone" line and set it to what you need.
[Test Case]
Set a timezone other than UTC using "dpkg reconfigure tzdata".
$ php -r 'echo date_default_timezone_get()."\n";'
Expected results: system timezone (eg. "Europe/London")
Actual results:
PHP Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Command line code on line 1
UTC
(where in this case UTC is the system timezone).
It's a simple question..but drive me 2 madness.
the result of this simple line of code:
echo gmdate('Y/m/d H:i:s');
... must output GMT time but it get it minus 1 hour!!!!!
So why??
Greenwich Mean Time has no "Summer Time" or "Daylight Saving Time" so depending on the season of the year these statements may produce the same or different output.
date_default_timezone_set('Europe/London');
echo gmdate('c');
echo date('c');
-- from the PHP manual (so, in addtion to the answer you get a clear RTM ;)
More information about timezones and daylight saving on SO.
Compare the output of your script with:
http://www.worldtimeserver.com/current_time_in_UTC.aspx
If it's wrong, the computer where you run the code is probably misconfigured.
So the clock is 18:37 right now in sweden but it prints out 16:37 why is that?
$timestamp = time();
date('M d, H:i', $timestamp)
What can be wrong?
Your date.timezone setting in your php.ini file is incorrect. Make sure that it is set to the proper value for your timezone:
date.timezone = Europe/Stockholm
If you do not have access to the php.ini file, you can use date_default_timezone_set() to set it during runtime:
date_default_timezone_set('Europe/Stockholm');
For a list of supported timezones, refer to the PHP Documentation.
If it still doesn't work, make sure your server is set to the proper timezone. If you've set the time manually and the timezone is incorrect (but since the time has been corrected manually it still shows the proper time), PHP has no way to get the UTC time properly and therefore returns the incorrect time.
It is possible that your server is located in a time that is 2 hour back from you.
You can use this page of the documentation to fix the timezone issue.
Try a line like this:
date_default_timezone_set('America/New_York');
Except, y'know, for Sweden.