如何获取本地服务器的时区? [英] How can I get the local server's time zone?
问题描述
如何获取本地服务器的时区而不依赖 php.ini
或其他配置文件?
How can I get the local server's timezone without relying on php.ini
or other configuration files?
我正在寻找类似于 date(' e')
。例如。 UTC,GMT或大西洋/亚速尔群岛。
I am looking for an output similar to the output of date('e')
. eg. "UTC", "GMT", or "Atlantic/Azores".
我需要知道这一点,以便我可以知道MySQL时区。
I need to know this so that I may know the MySQL timezone.
推荐答案
如果您使用的是基于Linux / Unix的托管平台,可以使用date命令的输出与字母时区缩写格式化因此:
If you're using a Linux/Unix based hosting platform, you could use the output of the date command with the "alphabetic time zone abbreviation" formatter as such:
$systemTimeZone = system('date +%Z');
但是,应该注意的是,您不一定要依靠系统的时区,而应该而是使用 date_default_timezone_set (或 date.timezone
php.ini设置)设置所需的时区。
However, it should be noted that you shouldn't necessarily rely on the system's timezone and that you should instead use date_default_timezone_set (or the date.timezone
php.ini setting) to set the required timezone.
这篇关于如何获取本地服务器的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!