PHP returning wrong current time
I'm having a problem using the function date
using the parameters to return the current time.
When I use the function:
$hora = date('H:i:s');
When I give a echo
in the variable $hora
to check, I have the following result:
14:45:21
But now it's 09: 45.
Is there any PHP or Xampp configuration that might be changing the schedule?
The date is returning correctly, but the time is not.
4 answers
In the php file.ini you have to change the timezone.
If you use Xampp you find the file in xampp \ php\php.ini
Just change the line below or add it there, after that restart XAMPP apache and try again.
date.timezone = America/Sao_Paulo
Is picking up the server time.
To fix just use PHP's date_default_timezone_set
.
For Brasilia Time use: 'America/Sao_Paulo'
. Other time zones you can find here .
The code will look like this:
date_default_timezone_set('America/Sao_Paulo');
$hora = date('H:i:s');
Use date_default_timezone_set('America/Sao_Paulo');
to configure your
Common error: change php code.ini of line 975 (more or less):
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Sao_Paulo // linha 975
But in fact you should change in line 1969:
[Date]
date.timezone=America/Sao_Paulo //linha 1969