This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
$date_orig = $dom->getElementById("Date")->nodeValue;
$date = date("Y-d-m H:m:s", strtotime($date_orig));
$query = $db->query("INSERT INTO records (`date`) VALUES ('".$date."')";


$date_orig的格式为“ 2012/12/31 11:23:00 PM”

我知道mysql日期时间的正确格式是Y-d-m H:m:s。为什么这不起作用?

最佳答案

这是错的

$date = date("Y-d-m H:m:s", strtotime($date_orig));


您应该使用“ i”分钟而不是“ m”。另外,您要添加前一天。应该是Y-m-d而不是o-Y-d-m

改成这个

$date = date("Y-m-d H:i:s", strtotime($date_orig));

关于php - PHP/MySQL-日期时间未正确插入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16229724/

10-16 17:33