我不小心将字符串转换为错误格式的日期(月份转换为日期)。这是我所做的:
DateTime::createFromFormat('d/m/Y', '12/26/1987')->format("d/m/Y");
所以它输出了错误的日期,从1987年12月26日变成了1989年10月2日,我已经将许多错误的日期保存到数据库中。 是否有任何反向方法或启示可以在转换之前获得原始日期。
提前感谢。
$date = DateTime::createFromFormat('d/m/Y', '12/26/1987');
$possible_dates = array();
$remainder_start = 0;
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
while ($remainder_start <= $days_in_month[intval($date->format("m")])
{
$possible_dates[] = DateTime::createFromFormat("m/d/Y", $date->format("d")."/".(intval($date->format("m"))+$remainder_start)."/".(intval($date->format("Y"))-($remainder_start/12)));
$remainder_start += 12;
}
foreach ($possible_dates as $d)
{
echo $d->format("m/d/Y")."\n";
}
1989年12月02日 1988年12月14日 1987年12月26日
由于您将日期放在天的位置,因此即使在错误的日期中,您的月份始终是正确的,但您的年份和天数将是几种组合之一。
12/26/1987
或10/02/1989
这两个日期? - Matt