首页 > 解决方案 > MySQL时间和PHP时间相差35秒

问题描述

MySQL:

exec("SET time_zone='+05:30';");
now();

PHP:

date_default_timezone_set("Asia/Kolkata");
echo $current_time = date('Y-m-d H:i:s ', time());

MySQL 将正确的时间设置为 IST,但 PHP 显示的时间比 IST 晚 35 秒。为什么这样?

标签: phpmysqldatetimetimezone

解决方案


您确定要同时执行这两个代码吗?有两种可能: 1. 执行时间不同。2. php.ini 文件中定义的 date_default_timezone_set() 错误。


推荐阅读