我该如何解决这个问题 PHP 谁能帮助我

时间:2021-06-14 07:48:36

标签: php

<body>   
    <?php
        $t1= $_POST['t1'];
        $t2= $_POST['t2'];

        $datetime1 = new DateTime($t1);//start time
        $datetime2 = new DateTime($t2);//end time
        $interval = $datetime1->diff($datetime2);
        echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');//00 years 0 months 0 days 08 hours 0 minutes 0 seconds
        // put your code here
        ?>
    <input type="time" name="t1">
    <input type="time" name="t2">    
</body>
Warning: Undefined array key "t1" in D:\xampp\htdocs\ITC\index.php on line 14
Warning: Undefined array key "t2" in D:\xampp\htdocs\ITC\index.php on line 15 00 years 0 months 0 days 00 hours 0 minutes 0 seconds

1 个答案:

答案 0 :(得分:0)

使用 method="post" 将两个元素放在一个表单中

像这样:

    <form method="post" action="">
    <input type="time" name="t1">
    <input type="time" name="t2">
    </form>