问题描述
这是我的问题:
echo date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s', mktime());
echo exec('date');
输出是:
2012-03-21 08:45:51
2012-03-21 08:45:51
Wed Mar 21 10:45:51 EDT 2012
服务器时间从php date()返回的时间开始2小时;或任何其他php日期/时间功能。这是因为服务器时间设置为EST和PHP.INI date.timezone =America / Denver
Server time is off 2 hours from the time returned by php date(); or any other php date/time function. It happens because server time set to EST and PHP.INI date.timezone="America/Denver"
我需要使用date_default_timezone_set同步这两个,但是我不要提前知道有什么区别。
I need to synchronize those two, by using date_default_timezone_set, but I don't know in advance what is the difference.
除了调用exec还有其他方法可以获得本地服务器时间吗?
Is there any other way to get local server time besides calling exec?
UPD:我知道php.ini设置是错误的,我可以改变它。问题是这个脚本会工作没有人知道什么样的服务器。我不能去每一个人,并纠正php.ini文件。我也不提前知道这些服务器上的时区。
UPD: I know that php.ini setting is wrong and that I can change it. The problem is that this script will work on nobody knows what kind of servers. I can't go to each and every one of them and correct the php.ini file. I also don't know in advance what timezone will be on those servers. I need a dynamic solution that will work everywhere.
推荐答案
您可以更改ini日期时区并打印日期
you can change the ini date time zone and print the date
ini_set('date.timezone', 'America/Los_Angeles');
这篇关于PHP:如何从服务器读取当前的日期/时间,而不是从php.ini读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!