【发布时间】:2019-04-05 09:33:58
【问题描述】:
我正在使用库将Gregorian date 转换为我所在国家/地区的日期。
以下代码是我的编码示例:
Include_once("jdf.php");
$test_date = "2018-09-09 06:00:00";
$changed_date = jdate('Y-m-d H:i:s', strtotime($test_date));
echo $changed_date;
但是当我将它用于数据库行时,只是 Y-m-d 变成了转换。
以下代码是我的脚本:
try {
$stmt = $conn->prepare("SELECT date as table_date FROM api_table;");
$stmt->execute();
Include("jdf.php");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$convert_date = jdate("Y/m/d H:i:s", strtotime($table_date));
echo $convert_date;
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
你们能帮帮我吗??
【问题讨论】:
-
你期望得到什么输出,你实际得到什么输出?
-
另外,api_table 中的“日期”列是什么数据类型?
-
@FabianGillenius 日期类型为
datatime并输出仅转换第一行的 H:i:s 并转换所有行 Y/m/d -
存储在数据库中的日期是否与 $test_date 相同?如果你同时回显 strtotime(),你得到相同的结果吗?
-
@FabianGillenius 这是在数据库中节省的时间:2018-09-06 08:13:24.700412 如果我删除
strtotime()我会收到这个错误:A non well formed numeric value encountered