手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

CentOS 下安装 LEMP 服务(Nginx、MariaDB/MySQL 和PHP)

[日期:2014-11-28] 来源:Linux中国  作者:Linux [字体:大 中 小]

How to set the default timezone in PHP

Question: How can I set the default timezone used by all date/time related PHP functions?

The default timezone for PHP is defined in php.ini configuration file. So you will need to edit the file by hand.

First, find the location of php.ini on your system as follows. In this example, it is found at /etc/php5/cli/php.ini.

$ php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:        /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/10-pdo.ini


Next, find out the timezone (TZ) string of your region. For that, you can use a command-line tool called tzselect. Simply run the following command:

$ tzselect

 
You will then go through interactive menu to identify your region.

How to set the default timezone in PHP 

After you are done, tzselect will print the value of TZ variable as follows. In this example, the TZ value is "America/New York".

How to set the default timezone in PHP 

Now open up php.ini in a text editor, and look up "date.timezone" variable in it. If "date.timezone" variable definition is commented out, uncomment the line. Then change the timezone accordingly. You are done!

date.timezone = "America/New_York"

linux
相关资讯       LEMP 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款