Php 更改sql查询的小时间隔

Php 更改sql查询的小时间隔,php,mysql,Php,Mysql,所以我页面上的日期格式显示了6小时前的时间。 如何更改它以显示正确的时间 这是我的问题 $query = "SELECT firstName,lastName, post,date_format(postDate,'%M,%d,%Y at %H:%i') as mydatefield FROM users INNER JOIN posts ON userId = empl_Id ORDER BY postDate"; 这会将值插入表中 $query

所以我页面上的日期格式显示了6小时前的时间。 如何更改它以显示正确的时间 这是我的问题

   $query = "SELECT firstName,lastName, post,date_format(postDate,'%M,%d,%Y at %H:%i') as     mydatefield
      FROM users INNER JOIN posts ON userId = empl_Id
      ORDER BY postDate";
这会将值插入表中

   $query = "INSERT INTO posts(postId,empl_Id,post,postDate)
        VALUES('','$empId','$idea',NOW())";
    $result = mysqli_query($db, $query);

假设您正在以UTC存储时间,并且您的位置比UTC晚6小时

不要更改您的查询。时区表示与应用程序的视图逻辑有关,而与控制器无关


每次在页面中显示日期/时间时,只需将TZ偏移量添加到UTC值。您可以在这里看到示例:

假定您以UTC存储时间,并且您的位置比UTC晚6小时

不要更改您的查询。时区表示与应用程序的视图逻辑有关,而与控制器无关

每次在页面中显示日期/时间时,只需将TZ偏移量添加到UTC值。您可以在此处看到示例:

如中所述,您可以按照所述操作

或者,作为州政府,您可以选择以下方式:

您可以使用DateTime::setTimezone()。如果UTC日期是UNIX时间戳,则可以使用以下代码:

$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp(1297869844); // this should be the 'current' then 
$date->setTimezone(new DateTimeZone('Europe/Paris'));

echo $date->format('Y-m-d H:i:s');
// Will print 2011-02-16 16:24:04
然后使用它将值插入数据库。 更改表示形式(在所有的unix时间戳之后,您甚至可能想要存储它,它只是被转换为一种人类形式作为一种说话方式)

如中所述,您可以按照所述进行操作

或者,作为州政府,您可以选择以下方式:

您可以使用DateTime::setTimezone()。如果UTC日期是UNIX时间戳,则可以使用以下代码:

$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp(1297869844); // this should be the 'current' then 
$date->setTimezone(new DateTimeZone('Europe/Paris'));

echo $date->format('Y-m-d H:i:s');
// Will print 2011-02-16 16:24:04
然后使用它将值插入数据库。
更改表示(在所有的unix时间戳之后,您甚至可能希望存储它,这只是将其转换为人类形式作为一种说话方式)

调整插入日期的时区。我该怎么做?我刚刚编辑了我的帖子,其中显示了插入查询调整插入日期的时区。我该怎么做?我刚刚编辑了显示插入查询的帖子