UNIX Timestamp - an hour off

Hello,

I have been having issues with a script that counts-down a timer. It has been found that it is apparently due to the systems UNIX Timestamp being off by one hour. (I am in America - New York, Eastern Standard or UTC -5)

I have confirmed that in virtualmin the correct timezone to be set. (America New_York Eastern Time ) On the System info page it is displaying the correct time / date. BUT I added the below line to my footer page in a site on the server and it gives me a timestamp of an hour earlier...

<!-- SERVER's UNIX TIMESTAMP: <?php echo time(); ?> -->

For example: At 3:35 (my real time) I checked this and got the UNIX timestamp of: 1329510902

Using: http://www.unixtimestamp.com/index.php This is the result: (1 hour off..) TIME STAMP: 1329510902 DATE (M/D/Y @ h:m:s): 02 / 17 / 12 @ 2:35:02pm EST

Any thoughts on where this issue could be and how to fix it? It is causing havoc on my sites.. Thanks a lot!

Scott

Status: 
Active

Comments

If you display the Unix time from the shell with a command like :

perl -e 'print time(),"\n"'

does it match what your PHP script shows?

Hi Jamie,

Yes it does show the same result running that command. 1 hour off..

I guess your system's time is out of sync then.

The quick fix is to run :

ntpdate pool.ntp.org

If that command is missing, run yum install ntpdate to install it.

Hmmm.

I am getting this:

[root@host01 ~]# ntpdate pool.ntp.org 17 Feb 19:35:58 ntpdate[13848]: the NTP socket is in use, exiting [root@host01 ~]#

I installed this before (i believe) through vmin via yum. It is set to the correct timezone... screenshots below..

Did i set it up wrong maybe? Thanks!

That error means that your system is running ntpd in the background, which should be syncing time for you already.

Try running :

/etc/init.d/ntpd stop
ntpdate pool.ntp.org
/etc/init.d/ntpd start

Wow, this is really strange.. After running the below i get the same results

[root@host01 ~]# /etc/init.d/ntpd stop
Shutting down ntpd:                                        [  OK  ]
[root@host01 ~]# ntpdate pool.ntp.org
17 Feb 20:33:50 ntpdate[15964]: adjust time server 64.16.214.60 offset -0.009433 sec
[root@host01 ~]# /etc/init.d/ntpd start
Starting ntpd:                                             [  OK  ]
[root@host01 ~]#

It didn't change anything.. Are there settings hidden somewhere that is making it think i am not on Eastern time maybe? I did check the php.ini through vmin and it is set to tthe same EST...

What is strange is that if i run date it gives me the right time but the timestamp still shows the hour offset..

[root@host01 etc]# date Fri Feb 17 21:00:06 EST 2012 [root@host01 etc]#

This is the output i get on my source page.. (a few seconds later)

Translation: TIME STAMP: 1329530432 DATE (M/D/Y @ h:m:s): 02 / 17 / 12 @ 8:00:32pm EST

Thanks -

So it looks like your system's time is correct, but PHP is not doing timezone conversions properly.

What line do you have in php.ini to set the timezone exactly? Generally that isn't needed, as PHP will pick up the system's timezone.

In my php.ini file the following is there:

I used vmin to select the zone - never did any manual edits if that matters..

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
; date.timezone = America/New_York

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-latitude
;date.default_latitude = 31.7667

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-longitude
;date.default_longitude = 35.2333

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.sunset-zenith
;date.sunset_zenith = 90.583333

Thx

Looks like those are commented out .. is date.timezone is set anywhere and not commented out?

If so, I'd recommend removing it, and restart Apache.

Do you know where I would be able to find if there is or a way to search for it? I haven't intentionally set anything or changed any files with this so I really just don't know if / how it would exist...

Thanks a lot.

I only have two domains on this box so i went in and edited the following files: (commented out all the date.timezone lines)

/etc/php.ini /home/domain1/etc/php.ini /home/domain1/etc/php5/php.ini

/home/domain2/etc/php.ini /home/domain2/etc/php5/php.ini

Then restarted apache, and i am still getting the same thing... 1hour off... from php...

I don't get it? Any other ideas? I am at a complete loss now..

Thank you

You may have to ask PHP experts about this one .... it seems that this is a PHP issue, rather than an Apache or Virtualmin bug.