php date/time output mismatches the one shown on my system - php

I changed the timezone setting on my php.ini (xampp server) to date.timezone=Asia/Kolkata.
On my index.php I have this
date_default_timezone_set("Asia/Kolkata");
echo date('d-m-Y H:i:sa');
Result, I get is, 12-08-2015 11:42:49am, where as the actual date time at the time of running this script is 11-08-2015 11:12pm.
The date and time is like 12 hours apart from what actually it is.
Can you help.

Check your system time, date and timezone in the windows control panel. Make sure it is accurate.

Related

PHP is giving unexpected results from epoch time conversion

I need to convert an epoch time to standard Hour and Minutes. Using various examples found on Stackoverflow, I have been unable to get the correct return. I am using the following
$seconds= 1495587600;
$mytime= date("H:i", $seconds);
echo $mytime."<br>";
I have checked the value of $seconds on a time converter site and get the correct result. I would expect the return from the code to be 09:00, instead I get 01:00. Is there something I am leaving out?
This looks like a time zone issue. PHP date() works using the local time zone which can be set with date_default_timezone_set(). Your hosting company or some other server configuration may be setting a different default time zone than what you expect.

get time and date in php

i am using
date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s');
but its always returning date and time form my PC.
Ex.. today is - 15/07/2015
and i changed my PC date to 17/09/2016
so php Date also returning same date...(17/09/2016)
is there any why to get real time and date?
what i have tried
1. simple date function
2. set timezone
3. i have searched on google but no luck yet...
It will always return your PC date as it well should.
Date & time functions use the server's date and time. So if you're running a local server (WAMP, XAMP or whatever) your PC will be the server and therefore it's time will be used.
Setting the timezone should change the time accordingly though.
There is nothing wrong with your code
date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s');
but as #Rizier123 said that if you are using XAMPP or WAMP or any other local server it will show the system time only. I would like to suggest you that put your code to an online server or use some online php compiler, then it will surely gonna give you the expected output.

how to set date and time not depending on computer date and time?

Please help,I want to set my webpage date not based on computer time because what if the user's time is not set correctly. i have tried searching in google but unfortunately did not get my answer.
I tried this code but when i change my pc date and time it also changes the output in my webpage to my pc time.
<?php
date_default_timezone_set('Asia/Manila');
$timezone = date_default_timezone_get();
echo date("Y/m/d H:i:s");
?>
This would hardly be a problem, as the website code is run on the website server, which has its very own time and date setting. As long as you make sure the date/time setting of the server is correct you will be fine.
The date/time setting of visiting users sure can differ a lot, depending on the user's geographical location. It may cause trouble when running JavaScript on a webpage, but for server code (e.g. PHP) it would be irrelevant.
The date will be set relative to the server that runs the code, if you run your code with a server instance on your computer, changing your computer date settings will afect your script but if you use a server wich is not on your computer the date setting that will be returned by your script will be the setting of your server not your computer's.

php date.timezone problem

i am storing member's created date using the time() function, and echo them back using strftime() and the date() function, but it doesnt display the right time information
my code is :
date("d-m-Y H:i:s", $member->created)
strftime("%Y-%m-%d",$member->created)
it should have displayed this:
17-11-2010 14:42
rather than:
17-11-2010 23:45
now, i have change my php.ini date.timezone configuration into my current time zone which is "Asia/Jakarta", yet nothing change. i have also try to set them manually inside my code using
date_default_timezone_set("Asia/Jakarta");
what did i miss ? please help me
Regards
EDIT:
according to Noodles, i need to check the server's clock setting, so i did using the
hwclock command, and it turns out that the clock setting is not right, since it displayed
Thu 18 Nov 2010 02:07:25 AM WIT -0.931691 seconds
while it should have been
Wed 17 Nov 2010 05:04:ss PM
now, how can i syncronize this setting into my timezone ??
Edit: i have manage to change the clock setting using
date -s "HH:MM:SS"
hwclock --systohc
thanks for pointing me out Noodles
case is closed i guess :D
thanks again guys
Are you sure your server's clock is set correctly? It would seem weird that the minutes would change. At the most I'd expect the hours to change if it was a different time zone, but not minutes.

Problem in DATE AND TIME

I am using date() function it getting the date and time as per my given format but the time its showing me is 4 hours forward than my current local machine time:
This is my code
echo date("Y-m-d h:i:s", time());
Its showing me : 2009-10-28 08:47:42
Where as it should Disply : 2009-10-28 04:47:42
Any Idea whats wrong with this and why its showing different time.
it is likely giving you GMT, you need to set your timezone: e.g. date_default_timezone_set('America/Los_Angeles');
http://php.net/manual/en/function.date-default-timezone-set.php
Make sure your time zone is set correctly:
e.g.
date_default_timezone_set('UTC');
It's returning the timezone of your server, not your computer
try http://www.php.net/manual/en/function.date-default-timezone-set.php
Because you are in, probably, US/Eastern (America/New_York, currently EDT) time zone, but the PHP you are using is running in UTC. You need to ensure that the TZ variable is set in the PHP environment.

Categories