Multiple PHP timezone

's Good to have a system where you have to use a timestamp in UTC format, and the use of a system that shows you when your profile has been viewed on site by ai to date with a timestamp, but I am having a problem on the site when you update it, it says that the profile has been update to 3 hours at the most, I need to use UTC, as it is required that the timezone information from an external api, how can I do to make this timestamp to a normal and work correctly in the site, showing that it was up-to-date on the time?

Author: Carlos Eduardo, 2017-10-13

2 answers

Carlos If I understood your question is this answer that will meet your need, first of all it would be ideal to take a look at the documentation and understand the operation of timezone and datetime of php.

In your system you should receive the variavel and Arrow - there with the desired timezone, in your case São Paulo.

new DateTimeZone('America/Sao_Paulo');

Receive the variavel per parameter and set the same with this timezone

$date = new DateTime('2017-10-14 10:04:59 GMT'); //entre os ( ) irá sua variável
$date->setTimezone($tz);

Ready your variavel has been set to the desired timezone, and at that moment you can use it to save in the bank, but it is important to read the documentation because at this moment you implement it in various ways, I did two ways just to exemplify your case, but in the documentation you will understand the various ways to do.

echo $date->format('Y-m-d g:i:s A');

Result: 2017-10-14 7:04:59 AM

echo $date->format('l F j Y g:i:s A');

Result: Saturday October 14 2017 7: 04: 59 AM

O full code looks like this:

$tz = new DateTimeZone('America/Sao_Paulo');
$date = new DateTime('2017-10-14 10:04:59 GMT'); // aqui dentro dos parenteses você deve coloca a sua váriavel DateTime($variavel);
$date->setTimezone($tz); //seta o timezone da váriavel
echo $date->format('Y-m-d g:i:s A'); //imprime o horário no padrão do timezone
echo '<br>';
echo $date->format('l F j Y g:i:s A');

And you can test on this link

 3
Author: WMomesso, 2017-10-14 13:36:47

You can change on the server, or in this way in php itself:

<?php
date_default_timezone_set('America/Sao_Paulo');
echo date('d/m/Y H:i:s');
?>

If you need other regions: http://br.php.net/manual/en/timezones.america.php

If you have access to server files:

Httpd.conf

SetEnv TZ America / Sao_Paulo

Php.ini

Data.timezone = "America / Sao_Paulo"

My.ini

Default-time-zone = "America / Sao_Paulo"

 1
Author: Wictor Chaves, 2017-10-13 12:54:52