我有一个来自 varchar 类型的数据库列的有效日期,全部采用 d/m/y 格式。然后,当我尝试使用 strtotime 函数和日期格式将其转换为日期格式时,我得到 01/01/70。我什至尝试用纯字符串值替换数据库结果。我已搜索并发现此链接 PHP strtotime 在日期列为空时返回 1970 日期 PHP:strtotime() 始终返回 01/01/1970 strtotime() 在以 dd/mm/yyyy 格式指定日期时不返回正确的值, 但两者没有帮助,因为数据不为空且格式有效。这是我的代码片段
if(isset($item['prep_date']) && $item['prep_date'] != NULL){
$trial=$item['prep_date'];
echo ": ".$trial;
$prepDate= strtotime($trial);
$prepDate = date('d/m/y', $prepDate);
echo "= ".$prepDate;
}
我错过了什么?这是两个回声的结果
28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 03/01/13= 01/03/13: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 18/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 02/09/13= 09/02/13: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 05/11/13= 11/05/13: 28/10/13= 01/01/70: 28/11/13= 01/01/70: 05/11/13= 11/05/13: 28/10/13= 01/01/70: 28/10/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 05/11/13= 11/05/13: 11/12/13= 12/11/13: 11/12/13= 12/11/13: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 11/12/13= 12/11/13: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 28/11/13= 01/01/70: 30/01/14= 01/01/70