PHP Countdown to Date

前端 未结 7 1661
深忆病人
深忆病人 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:19

    Let me play around like this:

    $rem = strtotime('2012-08-01 14:00:00') - time();
    $day = floor($rem / 86400);
    $hr  = floor(($rem % 86400) / 3600);
    $min = floor(($rem % 3600) / 60);
    $sec = ($rem % 60);
    if($day) echo "$day Days ";
    if($hr) echo "$hr Hours ";
    if($min) echo "$min Minutes ";
    if($sec) echo "$sec Seconds ";
    echo "Remaining...";
    

    Try this at your leisure... :-)

    NOTE: There is no if() test for echo "Remaining...", just coz you wont process this in case when $rem <= 0. Isn't it?

提交回复
热议问题