Should different servers translate unix timestamps as different dates?

While working on updating the user interface for the client, I noticed that the dates associated with all the articles were disabled for one day. I thought that during my changes I screwed something up, but, of course, threw together a small php test file that gave me some odd results. The test file is simple:

<?php $date = 1246053600; echo 'unix: ',$date,', converted: ',date('d/m/Y', $date); ?> 

If I run the above code on my local host, I get:

unix: 1246053600, converted: 06/26/2009

But if I run it on a production server, I get:

unix: 1246053600, converted: 06/27/2009

Pay attention to the difference in the day between the two? What's going on here?! Of course, converting a unix timestamp to a date does not have any server dependent dependencies?

+4
source share
3 answers

Your servers can be configured in two different time zones, and they interpret the timestamp as the number of seconds since midnight January 1, 1970 GMT. Dates cannot be turned off all day, but only a fraction of the day is enough to cross the border of midnight.

+4
source

The problem is that the value of the $ date you provide is assumed in UTC. If you use gmdate, you will get the same result on both servers. Otherwise, the displayed date and time will be adjusted according to the time zone of the servers. You can use the O (capital oh) code to print the time zone to clear the current settings on each server:

echo 'unix: ',$date,', converted: ',date('d/m/Y O', $date);

+4
source

I had a similar problem. I found that the time zone in php.ini from my development machine is different from the production server.

I would say it's worth checking it out.

+1
source

Source: https://habr.com/ru/post/1286740/


All Articles