As determined by time () the default time zone PHP

0

This question has arisen because of working with dates. The problem is the following; getting the current time from the function getdate() that takes the function time() returns me a time that has nothing to do with my time zone (UTC + 0) and when using the function 'date_default_timezone_get ()' to see the default time zone returns Europe / Berlin (UTC + 1)

Looking in the PHP documentation I found this appendix Date / Time Support where it is defined as determine the time zone.

Based on this I believe that the time zone is determining it and I quote;

  

"Magic" assumption (if allowed by the operating system)

Since I have not set the time zone, the TZ environment variable is not defined in my operating system (this I'm not sure of but I've reviewed it in the advanced configuration of windows 10) and that the time zone returns is not equal to UTC.

Where does this "mágina assumption" come from in the time zone?

    
asked by asantana o 30.04.2018 в 18:48
source

2 answers

1

To specify the time zone for format questions you must configure it in your php.ini file, looking for the line that says date.timezone = America/El_Salvador for example, then restart your server to take the changes.

Notice that it is not commented with ";" if you have it you should remove it

    
answered by 30.04.2018 / 20:16
source
1

Hello, very good! This problem can be solved like this:

First you have to know what is the time zone in which your server is configured by means of:

  

date_default_timezone_get() - > Go to the PHP page

Once you know the time zone determined by default on your server, you have to establish the zone that you want, by means of

  

date_default_timezone_set() - > Go to the PHP page

If you did not change the time zone, you have to go to the php.ini file and on the line where it says date.timezone you set the time zone that is the same as you had determined in date_default_timezone_set() .

To find out what your time zone is, you have to look for it in the PHP time zone

    
answered by 10.11.2018 в 04:08