我在 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/