Solved

One server converts epoch time incorrectly

Posted on 2013-01-18
8
667 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Fine Tune your automatic Updates for Ubuntu / Debian
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

691 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