mysql时间和php时间不一样

时间:2022-10-28 20:59:37

When I use current_timestamp with MySQL, I get the correct time, but when I use

当我使用current_timestamp和MySQL时,我得到了正确的时间,但是当我使用时

$mysqldate = date( 'Y-m-d H:i:s' );

$ mysqldate = date('Y-m-d H:i:s');

I get the date with with an hour delay (eg, 4:42 PM is 5:42 PM). I understood that both function use the server's local time - can someone explain the difference?

我得到了延迟一小时的日期(例如,下午4:42是下午5:42)。我明白这两个功能都使用服务器的本地时间 - 有人可以解释一下这个区别吗?

Thanks.

4 个解决方案

#1


9  

The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.

全局系统时间将通过/ etc / localtime文件设置,该文件将是符号链接或大多数系统上来自/ usr / share / zoneinfo /的区域文件的副本。应用程序将使用它作为默认值。

PHP can override this in a couple different ways:

PHP可以通过几种不同的方式覆盖它:

  1. date.timezone in php.ini
  2. php.ini中的date.timezone

  3. setting the TZ environment variable, e.g. putenv("TZ=US/Central");
  4. 设置TZ环境变量,例如运行putenv( “TZ = US /中心”);

  5. date_default_timezone_set function (in PHP >= 5.1.0)
  6. date_default_timezone_set函数(在PHP> = 5.1.0中)

MySQL can override this by running the following query immediately after connecting:

MySQL可以通过在连接后立即运行以下查询来覆盖它:

SET time_zone = 'US/Central'

#2


2  

There are php locale settings, it takes it from php.ini, not from system time

有php语言环境设置,它从php.ini获取,而不是从系统时间

#3


1  

Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.

也许您的PHP服务器认为它位于不同的时区,或者它使用不同的区域设置和夏令时规则。

#4


0  

Take a look at this article: http://www.devarticles.com/c/a/MySQL/Practical-Date-Time-examples-with-PHP-and-MySQL/

看一下这篇文章:http://www.devarticles.com/c/a/MySQL/Practical-Date-Time-examples-with-PHP-and-MySQL/

#1


9  

The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.

全局系统时间将通过/ etc / localtime文件设置,该文件将是符号链接或大多数系统上来自/ usr / share / zoneinfo /的区域文件的副本。应用程序将使用它作为默认值。

PHP can override this in a couple different ways:

PHP可以通过几种不同的方式覆盖它:

  1. date.timezone in php.ini
  2. php.ini中的date.timezone

  3. setting the TZ environment variable, e.g. putenv("TZ=US/Central");
  4. 设置TZ环境变量,例如运行putenv( “TZ = US /中心”);

  5. date_default_timezone_set function (in PHP >= 5.1.0)
  6. date_default_timezone_set函数(在PHP> = 5.1.0中)

MySQL can override this by running the following query immediately after connecting:

MySQL可以通过在连接后立即运行以下查询来覆盖它:

SET time_zone = 'US/Central'

#2


2  

There are php locale settings, it takes it from php.ini, not from system time

有php语言环境设置,它从php.ini获取,而不是从系统时间

#3


1  

Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.

也许您的PHP服务器认为它位于不同的时区,或者它使用不同的区域设置和夏令时规则。

#4


0  

Take a look at this article: http://www.devarticles.com/c/a/MySQL/Practical-Date-Time-examples-with-PHP-and-MySQL/

看一下这篇文章:http://www.devarticles.com/c/a/MySQL/Practical-Date-Time-examples-with-PHP-and-MySQL/