php - Mysql Current Timestamp 和 time() 显示不同的值

标签 php mysql codeigniter

好的。所以我一直在尝试实现一个计时器。现在发生了一件非常奇怪的事情,我不明白为什么?。

基本上,我试图找出上次访问时间和当前时间之间的差异。我将上次访问的时间存储在数据库中。这个值是根据服务器时间。但是当我尝试 php 的 time() 函数时,它显示的值比我在数据库中的时间晚了 5-6 小时。

例如:这是我的代码:

    $t1= strtotime($played_row->timer); // Time from the database with CURRENT_TIMESTAMP

    $t2= strtotime("now"); // Get the current time

它显示年:2012 月:01 日:t2 的 21 - 05:28 pm

年:2012 月:01 日:21 - 10:28 pm 我的时间戳值。

谁能告诉我这是为什么?

P.S:我在自己的计算机上运行代码。

最佳答案

我猜测您的数据库和 PHP 使用了两个不同的时区偏移量。

关于php - Mysql Current Timestamp 和 time() 显示不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8955038/

相关文章:

php - 在分页中突出显示当前页面?

mysql - 如何连接三个独立的 UPDATE 语句?

php - 数据库类型 int 使用值进行计算

php - ajax长轮询url/controller/method后面的数字?_xxxx

php - 使用 CodeIgniter + Facebook PHP SDK 时 : getUser() always returns 0

php - PayPal ReturnUrl 不传递参数

php - Codeigniter - 将多个数据数组传递给 View ?

php - 转换用于 MySQL FULLTEXT bool 模式的多词搜索字符串

php - 直接将数组插入MySQL数据库

php - SQL/PHP查询错误