【问题标题】:Issue in timestamp in MySQLMySQL中的时间戳问题
【发布时间】:2014-01-08 22:18:36
【问题描述】:

这是我的桌子

[ID] [TIMESTAMP]
[1] [2013-12-19 01:17:35] []
[2] [2013-12-19 01:23:42] []

这里显示的时间与我的时区不同。假设它显示的时间是 2013-12-19 01:17:35,但在我的时区,时间是 2013-12-19 13:47:35。

我的问题是我想获取我的时区的时间而不是默认的时间。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: php mysql timezone timestamp


    【解决方案1】:

    您需要更改 MySQL 中的时区。只需在你的根文件上写查询(可能是 index.php ) 更改 MySQL 中的时间戳。东京

    query("SET time_zone = 'Asia/Tokyo'");  //set your exact location
    

    编辑 确定你在哪里?见wikipedia 有关如何设置时区的更多详细信息?见how to set timezone of mysql?

    【讨论】:

      【解决方案2】:

      它以 UTC 存储,您可以在接收时转换回您的本地时区

      date_default_timezone_set('Asia/Tokyo'); // your reference timezone here
      
      $date = date('Y-m-d H:i:s');
      
      $date = /* SELECT date FROM database */;
      
      $usersTimezone = new DateTimeZone('America/Vancouver');
      $l10nDate = new DateTime($date);
      $l10nDate->setTimeZone($usersTimezone);
      echo $l10nDate->format('Y-m-d H:i:s');
      

      【讨论】:

      • 我可以更改 MySQL 中的时间戳吗?或者我只能在 php 中做到这一点?
      猜你喜欢
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 2011-03-16
      相关资源
      最近更新 更多