Why do I change the time when I insert?

2

Hello, I am handling a graph where the date and time are displayed and the parameters are clear, but at the moment of inserting the time and date, the time is advanced by 5 hours.

To insert I take the time and date of the current equipment and insert it in a Timestamp field, and in the database it is correctly captured the time and date it is, but by showing it in the graph it shows me 5 hours more . I leave the sample of the graph and abajito the real HR when inserting in a bd.

    
asked by Jonathan 19.07.2017 в 23:00
source

1 answer

1

It may be the problem with the time zone, try changing it with:

date_default_timezone_set()

Example working: See Online

date_default_timezone_set('America/Los_Angeles');

$d = new DateTime('now');
echo 'Zona America: ' . $d->format('d-m-Y H:i');

echo PHP_EOL;

date_default_timezone_set('Europe/Madrid');

$d = new DateTime('now');
echo 'Zona Europa: ' . $d->format('d-m-Y H:i');

// Resultado
// Zona America: 19-07-2017 14:13
// Zona Europa: 19-07-2017 23:13
    
answered by 19.07.2017 / 23:13
source