How to set PHP datetimezone?

How to set PHP datetimezone? If you are working with PHP datetime, then probably you need to need to set datetimezone in your configuration file or at the top of the file where you are using datetime php function. This PHP datetimezone sets the time zone where you are working, and we can also set this time zone with another php funciton date_default_timezone_set. Here we will see for both of them.

PHP datetimezone Example code snippet

If you don’t know, how to enter your timezone then you can get it here – List of Supported Timezones

$timezone = new DateTimeZone('Asia/Calcutta');

Set datetimezone with other php function

You can set time zone using this PHP function – date_default_timezone_set.

date_default_timezone_set syntax code

This variable $timezone_identifier is the value of the time zone, if you don’t the value of your timezone get it from here – List of Supported Timezones.

date_default_timezone_set($timezone_identifier)

date_default_timezone_set example code

And the example code for date_default_timezone_set is below:

date_default_timezone_set('Asia/Calcutta');

If you have any problem in setting up PHP datetimezone, then let me know using below comment form.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe