我正在使用下面的计算器来确定设定日期和当前日期之间的年,月和日。我以为它可以正常工作,但是后来又升到了年关,我注意到它工作不正常。明天实际上是一年的标记,但现在正在回归11 months, 34 days。谁能告诉我怎么了?应该是11 months, 30 days。function relationshipTimer($functionDate){ $date1 = $functionDate; $date2 = date("Y-m-d"); $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365 * 60 * 60 * 24)); $months = floor(($diff - ($years * 365 * 60 * 60 * 24)) / ((365 * 60 * 60 * 24) / 12)); $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24)); if ($years > 0) {echo $years . " Year";} if ($years > 1) {echo "s ";} if ($months > 0) {echo " " . $months . " Month";} if ($months > 1) {echo "s ";} if ($date1 == $date2) {echo "1 Day ";} if ($days > 0) {echo $days . " Day";} if ($days > 1) {echo "s ";}}这是$ functionDate的来源:relationshipTimer("2018-04-28");
1 回答
- 1 回答
- 0 关注
- 186 浏览
添加回答
举报
0/150
提交
取消