-4

计算自他或她出生年份以来的闰年总数。

来自用户的示例输入:1993,输出应为:2562

更新:

到目前为止,这是我的代码,如果特定年份是闰年,我创建了一个算法。

if($yr%4 == 0) {

 $leaps++;

}

考虑从 1993 年开始制作一个循环,并每年检查是否是闰年。

update2解决了。这就是我所做的。多谢你们

<?php 

    $dt = date("Y");

    $nm = $_POST['name'];
    $yr = $_POST['year'];
    $leaps = 0;
    $total = 0;
    $age = $dt - $yr;

    for($i = $yr; $i < $dt ; $i++) {

        if($i %4 == 0) {

            $leaps++;

        }

        $total = 366 * $leaps;
    }

    echo "Hi $nm, you are $age years old. There were $total since your birthday";   

?>

4

1 回答 1

0

这是您要查找的内容:

<?php

     $now = time(); // or your date as well
     $your_date = strtotime("1993-01-01");
     $datediff = $now - $your_date;
     echo floor($datediff/(60*60*24));

?>
于 2014-04-30T05:37:42.277 回答