To set the timezone in PHP, you can follow the following steps:
- Open your PHP file in a text editor or IDE.
- At the beginning of your PHP file, before any other code, add the following line of code:
date_default_timezone_set('America/New_York');
Replace ‘America/New_York’ with the timezone you want to set. You can find a list of supported timezones here: https://www.php.net/manual/en/timezones.php
- Save your PHP file.
- When your PHP code runs, it will use the timezone you specified in the date_default_timezone_set() function.
Note: If you have access to the php.ini file on your server, you can set the default timezone for all PHP scripts by adding the following line to the file:
date.timezone = "America/New_York"
Replace ‘America/New_York’ with the timezone you want to set. Save the php.ini file and restart your web server for the changes to take effect.