I have a question about date
, does it take the time of the server where my site is or the machine that the user is accessing?
I'm taking a look at the PHP Manual but I could not figure out which local method it refers to: machine or user.
I have a question about date
, does it take the time of the server where my site is or the machine that the user is accessing?
I'm taking a look at the PHP Manual but I could not figure out which local method it refers to: machine or user.
It refers to the date of the server. To adjust to a specific date and correct, use the function date_default_timezone_set , an example of working with São Paulo timetable
<?php
date_default_timezone_set('America/Sao_Paulo');
?>
To see the list of timezones
see PHP documentation
ps: always put this line at the beginning of your PHP code
I'm having a question about date, it picks up the server time where the is my site or the machine that the user is accessing?
The class or function DateTime / date gets the information (date or time) from the server that php is installed and not from the user's machine.
The time can be set using the timezone that is the time zone of a country or region, Brasilia time is the (GMT / UTC -3) three hours late compared to the greenwitch schedule.
Setting the time zone is a good idea because you should avoid the following error:
It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set () function.
This can be done in two ways the first is to assign a valid timezone in php.ini this setting will be valid for the whole server. The bottom line should be modified (after the restart restart the server):
date.timezone = America/Sao_Paulo
The second method is to use the date_default_timezone_set () function once called it only applies to the script.
date_default_timezone_set('America/Sao_Paulo');
You can use timezone
to get the schedule Do you want to:
setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
You can also define more specifically:
// set default timezone
date_default_timezone_set('America/Sao_Paulo'); // CDT
$info = getdate();
$date = $info['mday'];
$month = $info['mon'];
$year = $info['year'];
$hour = $info['hours'];
$min = $info['minutes'];
$sec = $info['seconds'];
$current_date = "$date/$month/$year == $hour:$min:$sec";
See more in this SOen response .