Solved

One server converts epoch time incorrectly

Posted on 2013-01-18
8
660 Views
Last Modified: 2013-01-18
Hi Experts,

We are having a VERY strange problem. One of our linux servers is converting epoch time into date incorrectly. It keeps being one day out.

For instance, 1364508000 converts correctly to 29 March 2013 on all of our servers, which is correct and is good Friday, but on our ONE server it converts to 28 March 2013. This is happening with all epoch stamps. It keeps converting to a day early. We are an office full of PHP developers and we are all stumped. I'm sure that this is problem on the linux server, but our linux administrator is being a little bitch, so now we have to try and fix it ourselves. ANY advice would be greatly appreciated.

Thank you in advance,
The entire Intoweb Team
0
Comment
Question by:Intoweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38792066
Check and compare the timezone settings on your servers.

echo $TZ

date +%Z
date +%z
0
 
LVL 4

Expert Comment

by:DanielSV
ID: 38792099
If the timezone is wrong, as woolmilkporc suggests, fix it like this.

CentOS, RedHat, etc.
sudo ln -sf /usr/share/zoneinfo/Continent/City /etc/timezone

Debian, Ubuntu, etc
sudo dpkg-reconfigure tzdata
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38792113
Where are you seeing this error?
0
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 

Author Comment

by:Intoweb
ID: 38792201
I am getting this error in all my PHP scripts where we run date("Y-m-d", $iTimestamp).

The timezones are correct, although the one was on GMT +2 and the other on UCT +0, but technically it's the same time. We changed them both to GMT +2 and I'm still getting this issue.

I also don't understand how timezone would have an impact on epoch conversion. It's supposed to calculate from 0:00 01/01/1970 regardless of the timezone....

I could understand if date("U") gave different epoch's due to timezone, but once the epoch has been established, how can it be that it calculated the date wrong based on that stamp?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38792241
<< I also don't understand how timezone would have an impact on epoch conversion <<

Seconds since epoch are computed relative to the local time be means of the localtime() function call.

The localtime() function converts the calendar time timep to broken-down time representation, expressed relative to the user's specified timezone.
The function acts as if it called tzset(3) and sets the external variables tzname with information about the current timezone, timezone with the difference between Coordinated Universal Time (UTC) and local standard time in seconds, and daylight to a nonzero value if daylight savings time rules apply during some part of the year.


Backwards coversion adheres to the same rule, of course, else you would get different results depending on the direction of the conversion.
0
 

Author Comment

by:Intoweb
ID: 38792279
Thanks, that makes sense, I guess. But the localtime and timezones are the same on all our servers, so that it not our problem.
0
 

Author Comment

by:Intoweb
ID: 38792284
I found it. The problem was caused by the timezone, but it was inside php.ini and not the server time itself. Thanks.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38794140
That's kind of what I was expecting.  One of the oddities about using timezones in PHP is that if you want just the date in a timezone that has "Daylight Savings Time", you need to ask what day it is at noon and not midnight.  The DST calculations around midnight will drive you crazy wondering what is going on, especially on the day it changes.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fine Tune your automatic Updates for Ubuntu / Debian
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question