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.
Related
I'm having a problem with the PHP date function which I've never had a problem with before.
The timestamp is entirely correct, however for some bizarre reason date() is outputting a time which does not correspond.
I have the following timestamp (and this is definitely the correct one - when I echo it out onto the page, as well as in the database, it shows as being correct):
464400
Yet when I use the following line of code:
<?php echo date("H:i",$timestamp); ?>
I'm getting a time of 4 am? If I paste the timestamp into a timestamp converter website, then it shows the time should in fact be 9am.
I'm completely stuck, this has never happened to me before & this problem has only just come up recently - the code hasn't been changed and everything seemed to be working correctly before.
Does anyone have any experience with this issue? Any help would be appreciated.
That time stamp is is 9am GMT timezone, if you are in another timezone then you will need to adjust it accordingly.
http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('Europe/London');
or even better in your php.ini
http://php.net/manual/en/datetime.configuration.php
date.timezone="Europe/London"
Or you can use more specifically GMT instead of Europe/London (which has DST)
try this method will work
for time zone
http://php.net/manual/en/timezones.php
code
<?php
date_default_timezone_set('Asia/Kolkata');
$dt2=date("Y-m-d H:i:s");
echo $dt2;
?>
try this
// set default timezone
date_default_timezone_set('UTC');
//define unix timestamp
$timestamp = 1456778973;
// output
echo date('d M Y H:i:s',$timestamp);
Try this converter too http://freeonlinetools24.com/
For time zone: https://www.php.net/manual/en/timezones.php
date_default_timezone_set('America/Chicago');
echo date("m/d/Y h:i:s A");
I have changed the way i save the time when a log is submitted to the DB by using the 'datetime' stamp in MySQL.
Im saving it in this format date("Y-m-d G:i:s"); which outputs it like so: 2012-02-22 20:20:01
The only problem is im in the UK, and my hosting/server isnt.
I have found out how to edit the time to bring it inline with UK time by doing this:
date = date("Y-m-d G:i:s", strtotime("+14"));
So now i have the time right i thought i would be ok, but now i have noticed that the date is not inline with UK date/time.
If i did a submission now it would display: 2012-02-22 20:25:36 when the time/date is actually 2012-02-23 20:20:01.
So it looks like that because my script is 14 hours behind, its knocking the date out to.
Is there a way i can fix it ?
Thanks, Sam!
include this in your program
date_default_timezone_set('Europe/London');
Add this one line in your php.ini file:
date.timezone = "Europe/London"
Now, anytime you use date or time functions, it will be adjusted to what you have specified.
For a complete list of timezones in Europe:
http://www.php.net/manual/en/timezones.europe.php
Utilizing the PHP Datetime module: Supported Timezones
$tz = new DateTimeZone('Pacific/Kiritimati'); // Change this to YOUR needed Timezone
$datetime_GMT = new DateTime(strtotime($server_or_SQL_date));
$datetime_GMT->setTimezone($tz);
$datetime_GMT->format("Y-m-d G:i:s");
echo $datetime_GMT;
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.
I'm using the unix timestamp to show when a message was posted in my project but when I came to displaying the exact time of the post I realized it was about 12 hours behind.
I'm in the UK and my server is in the US (might be the problem).
Is there a simple way of converting the unix timestamp into a readable British time?
$timestamp = time();
print date("F jS, Y", strtotime($timestamp));
Any help would be great,
Thanks!
At the top of your script, write:
date_default_timezone_set('Europe/London');
Or if your PHP is >= 5.2.0:
date_timezone_set('Europe/London');
Just call date_timezone_set with the appropriate parameter for the UK at the start of your script when displaying the dates (not when recording them; I 'm not sure, but it might result in the "wrong" timestamps being recorded).
Edit: The timezone you want is 'Europe/London'.
try date-default-timezone-set.
date_default_timezone_set('Europe/London');
Use date_default_timezone_set('Europe/London'); to set the time zone to London's time. Not sure if it works with summer/winter time.
the simplies way is to substruct gmt offset. e.g:
echo(date('Y-m-d h:i'), $myvalue - 60 * 60 * $nhours));
where $nhours - time defference in hours.
This one worked for me
date_default_timezone_set('Europe/London');
I dont know why I'm not getting the correct date and time in my region.
Here's the code
<?php
//date_default_timezone_set('Asia/Manila');
echo date('YYYY-mm-dd H:i:s'); ?>
Even if I comment out or change the time zone the date and time that I'm getting is still the same.
The date today is 23. But its outputting 22. And the time doesn't change even if I change the time zones.
Does it have something to do with my computer?
Because I sometimes notice that the clock on the lower right corner of the screen is not displaying the correct time.
Heres the current time, but its displaying this:
01-22-2011 05:38:31-PM
Are you sure that's the script producing the output shown?
echo date('YYYY-mm-dd H:i:s'); ?>
Doesn't seem to match the format of
01-22-2011 05:38:31-PM
Other than that, the timezone setting looks right.
It could be that time set up on server (where PHP script is being executed) is not correct.
Are you from the Philippines? This worked for me for some reason:
date_default_timezone_set('Asia/Tbilisi');
Asia/Manila is not working for me too. Just give it a try.