2月28日至29日之间的问题,请更改日期并查看结果
$cmncdate = '2019-02-29';
$time=strtotime($cmncdate);
$day=date("d",$time);
$mnth=date("m",$time);
if ($day>=1 AND $day<11)
{ $nday = '10'; $newDate = date("Y-m-$nday", strtotime($cmncdate));
echo $newDate; }
elseif ($day>10 AND $day<21)
{ $nday = '20'; $newDate = date("Y-m-$nday", strtotime($cmncdate));
echo $newDate; }
elseif ($day>20 AND $day<31 AND $mnth!=2)
{ $nday = '30'; $newDate = date("Y-m-$nday", strtotime($cmncdate));
echo $newDate; }
elseif ($day>20 AND $day<29 AND $mnth=2)
{ $nday = '28'; $newDate = date("Y-m-$nday", strtotime($cmncdate));
echo $newDate; }
elseif ($day=29 AND $mnth=2)
{ $nday = '29'; $newDate = date("Y-m-$nday", strtotime($cmncdate));
echo $newDate; }
答案 0 :(得分:0)
问题在于2019-02-29
是无效日期。第29个仅在leap年(2012、2016、2020等)上有效。因此日期会自动移至1/3/2019
...
$cmncdate = '2019-02-29';
$time=strtotime($cmncdate);
$day=date("d",$time);
$mnth=date("m",$time);
echo $mnth.".".$day;
给予...
03.01
因此,尝试使用2020年...
$cmncdate = '2020-02-29';
$time=strtotime($cmncdate);
$day=date("d",$time);
$mnth=date("m",$time);
echo $mnth.".".$day;