weixin_33696822 2019-11-06 01:00 采纳率: 0%
浏览 51

DateTime PHP的问题

I have made a chat using php, sql and ajax. All the message are stored in DB with a datetime format like this 0000-00-00 00:00:00. The issue: every day, from midnight (00:00:00) to 00:59:59 the messages are stored in DB, but not visualized in chat. In the rest of the day it work perfectly. I think it depend on UTC time zone. My timezone is UTC +1 (so the day doesn't go from 0 to 23, but from 1 to 0).

Actually I use this PHP code:

$now = new DateTime(null, new DateTimeZone('Europe/Rome'));
$now = $now->format('Y-m-d H:i:s');

The column where I store this datetime:

'time' datetime NOT NULL DEFAULT '0000-00-00 00:00:00'

The date are always stored correctly. Someone can help me?

EDIT: to call data stored I use this:

$datetime="SELECT var1, var2, time FROM chat WHERE time >= DATE_SUB(NOW(),INTERVAL 1 HOUR) ORDER BY time ASC";
$datetimeX = $db->prepare($datetime);
$datetimeX->execute();

while($row = $datetimeX->fetch(PDO::FETCH_ASSOC)) {

echo "<span style='color:#f2f2f2;'>" . $row['time'] . " </span>";

//other stuff
}
  • 写回答

2条回答 默认 最新

  • weixin_33711647 2019-11-06 01:24
    关注

    You may try this

    $dateTimeZone = new DateTimeZone("Europe/Rome");
    $dateTime = new DateTime("now", $dateTimeZone);
    $Offset = $dateTimeZone->getOffset($dateTime);
    $now = date("Y-m-d H:i:s", time() + $Offset);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表