View Full Version : Php time 2 hours different
keyboard
04-22-2012, 04:34 AM
$date = time();
echo date("j F Y - g:i a", $date);
outputs
22 April 2012 - 2:27 pm
when it should output
22 April 2012 - 12:27 am
I'm running this on WAMP on my home computer. Any help?
djr33
04-22-2012, 05:19 AM
Is this an example of the problem or a specific problem for the date() function?
It sounds to me like either your PHP configuration either is set to the wrong timezone, or your default active timezone in PHP is wrong.
Those sound similar, but they're not. PHP knows what time it is. But that might be wrong (off by 2 hours). And/or when you use date() it uses whatever timezone setting is active, usually determined by a default timezone, relative of course to PHP's base time setting. In other words, does PHP not know the right time, or does PHP just think you want to output time for somewhere else?
Of course it could also be a server-level problem. Maybe check your logs to see if the logs also have weird times on them.
You can try to figure out the details and fix them, or you can just set another timezone during runtime (or via .htaccess, or php.ini).
keyboard
04-22-2012, 05:52 AM
This is an actuall problem I'm having. I'll have a go at what you suggested and get back to you.
djr33
04-22-2012, 06:29 AM
My first sentence wasn't clear-- I was asking whether you were using date() to demonstrate the problem (with the server in general) or if this problem was specific (and limited to) the date() function.
But that's fine-- post back when you know more and I'll see if I can think of anything. Unfortunately with something like this, it ends up often just being a lot of trial and error until you eventually find the source of the problem.
keyboard
04-22-2012, 07:03 AM
I believe it is a problem with time() in general not just date().
james438
04-22-2012, 07:13 AM
What happens when you set the timezone with the following at the top of your script?
date_default_timezone_set('America/Chicago');
You could also add the same thing to your php.ini file. It would look like the following though:
date.timezone = "America/Chicago"
If you are making this change to your php.ini file the changes may not take place right away depending on your hosting service. I use godaddy and in order for the changes to take place immediately I go to the godaddy website, access my hosting service and select end system processes. You might not have a godaddy hosting account, but a number of people do. If you need more details with how to do what I just described let me know and I can give a more detailed answer.
I might be totally barking up the wrong tree with this post though.
jscheuer1
04-22-2012, 07:48 AM
Why Chicago? keyboard1333's location puts him in the Mariana Trench. I suppose that's some sort of reference to something else though. Where are you really? That's where you should be setting your timezone for. See:
http://www.php.net/manual/en/timezones.php
for the list of supported zones.
keyboard
04-22-2012, 08:20 AM
Why Chicago? keyboard1333's location puts him in the Mariana Trench. I suppose that's some sort of reference to something else though.
It's called a joke :D
and I'm guessing because he was using his hometown as an example??? (correct me if I'm wrong)
Thanks for all the suggestions guys. I'll have a go to setting the timezone later. Thanks again.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.