This article will help you to how to set or get timezone in a php script using date_default_timezone_set() and date_default_timezone_get() inbuilt php functions.
Advertisement
How to Set Timezone in PHP Script
You can set default timezone in a single php script using date_default_timezone_set() function. This timezone is used as default timezone for other functions of php script.
First choose correct timezone for your php script to use. Use below link to find out list of time zones available in php.
Now edit php script and add below line at top of script with preferred timezone. For example you select “America/New_York” as your default timezone.
<?php date_default_timezone_set("America/New_York "); ?>
How to Get Default Timezone of PHP
To get current set default timezone in php use date_default_timezone_get() function anywhere inside your php script. for example –
<?php echo date_default_timezone_get(); ?>
1 Comment
Great tutorial. This tutorial was really useful to set default timezone in php file.
Thanks.