PHP Countdown to Date

前端 未结 7 1681
深忆病人
深忆病人 2020-12-03 01:30

How could set a date and get a countdown in PHP? For example if I set the date as 3 December 2PM it would tell me how many days and hours are remaining.

No need for

7条回答
  •  盖世英雄少女心
    2020-12-03 02:25

    You can use the strtotime function to get the time of the date specified, then use time to get the difference.

    $date = strtotime("December 3, 2009 2:00 PM");
    $remaining = $date - time();
    

    $remaining will be the number of seconds remaining. Then you can divide that number to get the number of days, hours, minutes, etc.

    $days_remaining = floor($remaining / 86400);
    $hours_remaining = floor(($remaining % 86400) / 3600);
    echo "There are $days_remaining days and $hours_remaining hours left";
    

提交回复
热议问题