Search code examples
phppear

PHP log time 2 hours out from system time in localhost


Im using ( and is new to ) PEAR. When inserting, the time stamp is two hours earlier than my system time (running in localhost)

When writing to LogEvent table on my DB, I do the following

$le = new LogEvent;
$le->userID = $_SESSION['userID'];
$le->event = $msg;
$le->priority = (int)$priority;
if ($le->priority > 0) {
    $le->insert();
}

inside the LogEvent class the insert() looks like this

function insert() {
    $this->timestamp = date('Y-m-d H:i:s');
    $le = parent::insert();
    return $le;         
}

The DB is on a VM Linux server on time ( SYSTEM +2 : e.g. 06:00)
MY Windows LOCALHOST is running on well system time ( SYSTEM +0 : e.g. 04:00)
This insert writes the time in system min 2 ( SYSTEM -2 : e.g. 02:00)

why does this date('Y-m-d H:i:s') give me the wrong time. If its running as or in localhost, should it not take my local system time?

Or am I overlooking something really obvious?


Solution

  • PHP Timezone - runtime

      date_default_timezone_set('Europe/London');
    

    PHP Timezone - php.ini

      date.timezone = "Europe/London"