Search code examples
phplinuxdatetimesles

Strange issue with date and time in php on linux


i've search a lot but i could not find an answer to this problem. I've set correctly the timezone on the server and for php. As i use "date" commmand on the server it gives me the right answer. But if i use this PHP script:

<?php
// include 'cal_config.php';
// include 'cal_matchclass.php';

// $_mail = $_GET["mail"];

$dataTime = date("Y-m-d H:i:s");
echo $dataTime;
echo "\n".date_default_timezone_get();

?>

the date/time it shows me is 6 hours later! but the timezone is correct (in this case it is Europe/Rome).

Anyone has some suggestions? Pls help because i really cannot understand what's wrong as i set all things right. Thanks all.

This is the output from "date" command on linux:

mar  5 ago 2014, 18.06.15, EDT

And this is the output from the above php script:

2014-08-06 00:06:12
Europe/Rome

Solution

  • EDT = Eastern Daylight Time (UTC - 4 hours)

    Europe/Rome = +2.0 hours

    Their time sum gives you exactly six hours difference.