gpt4 book ai didi

php - 将 pubdate 或 timestamp 插入数据库

转载 作者:行者123 更新时间:2023-11-30 23:31:24 25 4
gpt4 key购买 nike

从 rss 提要我有 pubdate 以及时间戳:

pubdate:
Thu, 03 May 2012 09:00:00 +0000
timestamp:
1336035600

然而,当我将它插入数据库时​​,它总是:0000-00-00 ETC。这是查询:

    $query = "INSERT INTO adafruit_articles VALUES ('', '$title', '$link', '$comments', '$timestamp', '$description', '$content')";

enter image description here

我的数据库设置是否正确?

最佳答案

您需要将其转换为 MySQL 友好的格式。将时间戳传递给 date() 函数使这变得简单:

echo date("Y-m-d H:i:s", 1336035600);

或者使用 DateTime对象:

$date = new DateTime(1336035600);
echo $date->format('Y-m-d H:i:s');

关于php - 将 pubdate 或 timestamp 插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10432074/

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