Php Set TimeZone

爷,独闯天下 提交于 2019-12-05 22:32:58

use this line in your codes

date_default_timezone_set("Asia/Karachi"); 

like

  <?php 
    date_default_timezone_set("Asia/Karachi"); 
    echo date('d-m-Y H:i:s'); 
?>

Method 1 (Editing Php.ini)

1) Open your php.ini file

2) Add the following line of code to top of your php.ini file

date.timezone = "Asia/Karachi"

3) Restart php.

Note: You can find a list of timezone here: http://php.net/manual/en/timezones.asia.php

Method 2 (Using date_default_timezone_set)

In case you don't have access to the php.ini file, you can use date_default_timezone_set("Asia/Karachi"). Just put it in the entry point of your application.

http://php.net/manual/en/function.date-default-timezone-set.php

It is better to keep it in the config file because even if you use the same function somewhere else, you will have to re-declare this statement.

  date_default_timezone_set("Asia/Karachi"); 

If you are using any framework like yii, CI or cake php.. keep this line in index.php file which basically later on loads rest of the framework.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!