...

View Full Version : PHP time 1 hour fast.



rafiki
02-19-2008, 05:23 PM
when i use a standard PHP date statement


$date = date('l dS \of F Y h:i:s A');
echo "$date";
the time is 1 hour fast of my local time.
any ideas on how to make the h (hour) -- (minus)
solved.


$date = date('l dS \of F Y h:i:s A', -time(3600));

CFMaBiSmAd
02-19-2008, 05:50 PM
The date() function adjusts for the local time on the server, including any daylight saving time shifts. If you want to make your server appear to be in a different time zone than what it really is, either set the date.timezone parameter in a php.ini or .htaccess file or use the date_default_timezone_set() function in your script -

http://www.php.net/manual/en/ref.datetime.php#ini.date.timezone
http://www.php.net/manual/en/function.date-default-timezone-set.php

rafiki
02-19-2008, 05:55 PM
problem im using 4.4.7
my host does offer 5.2.3, but not sure how to activate it.

Andrew Johnson
02-19-2008, 06:38 PM
$date = date('l dS \of F Y h:i:s A', time() - 3600);

aedrin
02-19-2008, 10:27 PM
That's a classic case of 'fixing the symptom, not the problem' which is a bad thing.

Andrew Johnson
02-19-2008, 10:44 PM
Solution Two: Turn back the clock on your server...

We should make a spam-only thread so aedrin can just post in there all day to crank up his post count, instead of saying things that are completely unhelpful.

oracleguy
02-19-2008, 11:25 PM
Aedrin is technically correct, that solution does only fix the symptom but not the cause. Which is something valid to point out in case the OP doesn't realize it.

However Aedrin you could have phrased it more diplomatically or suggested an alternate solution that fixes the root cause.

Andrew Johnson, while he could have been more helpful, his point is still valid. Insinuating that all he does is spam the forum is just as wrong as what he did.

Everyone just play nice.

rafiki
02-20-2008, 02:59 AM
when i use a standard PHP date statement


$date = date('l dS \of F Y h:i:s A');
echo "$date";
the time is 1 hour fast of my local time.
any ideas on how to make the h (hour) -- (minus)
solved.


$date = date('l dS \of F Y h:i:s A', -time(3600));


andy you didn't just post what i did now whos spamming?
i just want to say if its aedrin, then its you aswell.

aedrin
02-20-2008, 06:58 PM
However Aedrin you could have phrased it more diplomatically or suggested an alternate solution that fixes the root cause.


We should make a spam-only thread so aedrin can just post in there all day to crank up his post count, instead of saying things that are completely unhelpful.

I will only post what I find helpful/beneficial. This doesn't mean it has to be helpful for everyone (except perhaps the OP).

I didn't think my comment was offensive or too forward, I was pointing out a problem that a lot of people don't consider. It was on topic and there was value in it. Hence it can't be considered spam. And there is little point in insinuating topic count is my reason to post. I post here to improve my knowledge of PHP by looking at problems I don't come across in my domain and figuring out solutions without being the designer of the code.


Solution Two: Turn back the clock on your server...

This has the same issue. Fixing the symptom, not the problem.

Symptom: The time shows up an hour off.
Problem: The server is configured to display the wrong timezone.

These should've been known at the time the thread was started (basic time keeping concepts).

It's easy to determine that the solution needed is to figure out how to choose a right/better timezone.

For instance, choosing a different timezone at the top of your main script. PHP has multiple ways of choosing this. Whether the version of PHP that is used supports these methods is something the OP can find out for himself. Much better than us, in any case (since we do not have access to the server).

A lot of my response is based on the OP's personal input. If someone just states the original problem they're having and asks for the solution, I have little reason to give more than 1-2 lines of response. If someone figured out the problem and need help with the solution, and show what they have come up with so far, then I'm willing to put some coding effort into it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum