gpt4 book ai didi

php - 无法在 mysql 中存储日期和时间戳值

转载 作者:行者123 更新时间:2023-12-01 00:27:35 26 4
gpt4 key购买 nike

我在 mysql 表中有日期和时间戳字段。

$timeString="Thu Jul 26 22:45:09 +0000 2012";

$time=strtotime($timeString);

$date=date('Y-m-d', $timeString);

当我执行查询时,它存储以下值:

日期 0000-00-00时间 0000-00-00 00:00:00

谁能解决我的问题。

最佳答案

您正在尝试从 $timestring(字符串)而不是 $time(时间戳)构建日期

尝试:

$timeString="Thu Jul 26 22:45:09 +0000 2012";

$time=strtotime($timeString);

$date=date('Y-m-d', $time);

您应该在您的开发环境中启用 php 警告。日期会告诉你:)

date() expects parameter 2 to be long, string given

关于php - 无法在 mysql 中存储日期和时间戳值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11694827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com