我正在使用引导日期时间选择器,当我尝试插入选定的日期时间时,它向我显示错误
"SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:第 1 行的"开始日期"列的"开始日期"的"2012 年 12 月 21 日 - 03:25 PM"
然后我在我的控制器中使用
$iVisitors->startDate = date("Y-d-m H:i:s", strtotime(request('startDate')));
但现在它存储默认时间 1970-01-01 00:00:00 不是我选择的时间。如何存储我选择的日期时间?
传递给 php 的 strtotime(( 的日期时间格式是错误的。您可以使用 php 的 str_replace(( 简单地将时间之前出现的-
替换为空字符串,即
$iVisitors->startDate = date("Y-d-m H:i:s", strtotime(str_replace('- ', '', request('startDate'))));
这样21 December 2012 - 03:25 PM
现在变得21 December 2012 03:25 PM
.
你得到1970-01-01 00:00:00
,因为strtotime返回false,所以php的日期也返回它的开始日期。
您可以查看 strtotime php 手册页以获取更多信息。您还可以通过设置可接受的格式来轻松指定从日期选取器脚本返回的格式。