How to set or get default timezone in PHP

Today we are going to explain to you how to set or get a default timezone in PHP. If you are looking to change the default timezone for all date and time in PHP then here you will find the solution.

Using php built-in function date_default_timezone_set() and date_default_timezone_get() we can set and get default timezone respectively.

You can also find the similar articles about the Time Zone and DateTime.

Timezone in PHP

  1. Set default timezone
  2. Get default timezone

1. Set default timezone in PHP

To set the default timezone, we need to edit the php script and add below line at top of the script.

Example

Here, we have printed the date after setting the timezone so we can check that we are getting the correct time as we have set the timezone.

2. Get default timezone in PHP

You can get the current timezone using date_default_timezone_get() function anywhere in php script.

Example

Here you will find the list of the available timezone in PHP.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *