Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should different servers translate unix timestamps as different dates?

Whilst working on a UI update for a client, I noticed the dates associated with all the articles were out by a day. I figured I'd screwed something up during my changes, but to be sure, threw together a little php test file that gave me some odd results. The test file is just;

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

If I run the above code on my localhost I get:

unix: 1246053600, converted: 26/06/2009

But if I run it on the production server I get:

unix: 1246053600, converted: 27/06/2009

Notice the day difference between the two? What's happening here?! Surely converting a unix timestamp to a date doesn't have any server specific dependancies?

like image 424
Mathew Avatar asked Jan 24 '23 11:01

Mathew


1 Answers

Your servers might be set to two different time zones, and they're interpreting the timestamp as the number of seconds since midnight january 1st 1970 GMT. The dates may not be off by a whole day, but just part of a day, enough to make it cross over the midnight boundary.

like image 86
Breton Avatar answered Jan 26 '23 02:01

Breton