Welcome Guest, Not a member yet? Register   Sign In
Date and Timezone handling confusion
#1

[eluser]Jakobud[/eluser]
My timezone is America/Denver. My servers timezone is America/Chicago.

My phpinfo() says:

Code:
Default timezone    America/Chicago

Current Time:
Code:
Local: 11:37 AM, 8-24-2010
Server: 12:37 AM, 8-24-2010
UTC/GMT: 5:37 PM, 8-24-2010

In config.php, if I set

Code:
$config['time_reference'] = 'local';

from what I understand, this should make now() give me a unix timestamp for the local (server) timezone, which is America/Chicago. So I run the following code:

Code:
$this->load->helper('date');
echo now();

and I get this:

Code:
1282671430 = 5:37 PM, 8-24-2010

(I'm using http://www.epochconverter.com/ to tell me the conversion)

So... its giving me UTC time even though the config says to give me the local time?

Oddly though on top of this, if I run unix_to_human(now()), it tells me the correct time/date (server time):

Code:
2010-08-24 12:37 PM

If I set

Code:
$config['time_reference'] = 'gmt';

and run the same code again, I get

Code:
1282689463 = 10:37 PM, 8-24-2010

But unix_to_human(now()) gives me the correct UTC/GMT time:

Code:
2010-08-24 05:37 PM

which doesn't match up with anything. It looks like it tried to offset the difference between American/Chicago and UTC. But if the 'local' now() is already giving me UTC timestamp, then this value doesn't really have any use.

Am I missing something obvious here? Are websites like http://www.epochconverter.com/ converting UNIX time to Human time incorrectly?

UNIX TIME is defined as "the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970". Seems like now() should give you the same unix timestamp no matter what timezone you are in. Shouldn't it always be UTC time no matter what?
#2

[eluser]WanWizard[/eluser]
What does time() give you?

Because if time_reference != 'gmt', now() just returns time().
#3

[eluser]Jakobud[/eluser]
time() gives just the local server unix timestamp (12:37 AM, 8-24-2010 in the example above).




Theme © iAndrew 2016 - Forum software by © MyBB