PASSWORD RESET

Your destination for complete Tech news

PHP

How to set a default timezone in PHP?

434 0
< 1 min read

To set the default timezone in PHP, you can use the date_default_timezone_set function. This function takes a timezone identifier as an argument and sets the default timezone for all date and time functions in your script.

Here is an example of how to use the date_default_timezone_set function to set the default timezone in PHP:

date_default_timezone_set('America/New_York');

This will set the default timezone to Eastern Time (ET).

You can also set the default timezone in the PHP configuration file (php.ini) by setting the date.timezone directive:

date.timezone = America/New_York

This will set the default timezone for all PHP scripts on the server.

You can find a list of valid timezone identifiers in the PHP documentation. It’s important to note that the timezone identifier is case-sensitive.

It’s generally a good idea to set the default timezone in your PHP scripts, as this ensures that all date and time functions will use the same timezone and helps to avoid potential issues with inconsistent timezones.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.