I'm testing out making an entry system but the problem is, my host's timezone is different from where I live. It's 3am on my server while on my local computer, the time is 4pm. How do I automatically adjust code that I pull from the database to be displayed as a timezone similar to where I'm at?
我正在测试一个进入系统,但问题是,我主人的时区与我住的地方不同。在我的服务器上是凌晨3点,而在我的本地电脑上,时间是下午4点。如何自动调整从数据库中提取的代码,使其显示为类似于当前位置的时区?
1 个解决方案
#1
3
You can set the default timezone using the function date_default_timezone_set(). It sets the default timezone used by all date/time functions in a script.
可以使用函数date_default_timezone_set()设置默认时区。它设置脚本中所有日期/时间函数使用的默认时区。
date_default_timezone_set('America/Los_Angeles');
Have a look at this page:
请看这一页:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/function.date-default-timezone-set.php
You can find a list of timezones here
你可以在这里找到一个时区列表
http://php.net/manual/en/timezones.php
http://php.net/manual/en/timezones.php
Alternatively you could change the php.ini file if you have the permissions for it. You could change the option date.timezone to your timezone like this:
您也可以更改php。ini文件,如果您有权限的话。您可以更改选项日期。你的时区是这样的:
date.timezone = "US/Central"
For more information about date.timezone, go to this website:
有关日期的更多信息。时区,登陆本网站:
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html
#1
3
You can set the default timezone using the function date_default_timezone_set(). It sets the default timezone used by all date/time functions in a script.
可以使用函数date_default_timezone_set()设置默认时区。它设置脚本中所有日期/时间函数使用的默认时区。
date_default_timezone_set('America/Los_Angeles');
Have a look at this page:
请看这一页:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/function.date-default-timezone-set.php
You can find a list of timezones here
你可以在这里找到一个时区列表
http://php.net/manual/en/timezones.php
http://php.net/manual/en/timezones.php
Alternatively you could change the php.ini file if you have the permissions for it. You could change the option date.timezone to your timezone like this:
您也可以更改php。ini文件,如果您有权限的话。您可以更改选项日期。你的时区是这样的:
date.timezone = "US/Central"
For more information about date.timezone, go to this website:
有关日期的更多信息。时区,登陆本网站:
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html