PHP Countdown to Date

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

    Did this countdown until the end of the semester:

        $endOfSemester = mktime(15,30,0,5,21,2015);
        $now = time();
        $secondsRemaining = $endOfSemester - $now;
    
        define('SECONDS_PER_MINUTE', 60);
        define('SECONDS_PER_HOUR', 3600);
        define('SECONDS_PER_DAY', 86400);
    
        $daysRemaining = floor($secondsRemaining / SECONDS_PER_DAY); //days until end
        $secondsRemaining -= ($daysRemaining * SECONDS_PER_DAY); //update variable
    
        $hoursRemaining = floor($secondsRemaining / SECONDS_PER_HOUR); //hours until end
        $secondsRemaining -= ($hoursRemaining * SECONDS_PER_HOUR); //update variable
    
        $minutesRemaining = floor($secondsRemaining / SECONDS_PER_MINUTE); //minutes until end
        $secondsRemaining -= ($minutesRemaining * SECONDS_PER_MINUTE); //update variable
    
        echo("<h3>There are $daysRemaining days, $hoursRemaining hours, $minutesRemaining minutes, $secondsRemaining seconds until the end of the semester</h3>"); //print message
    
    0 讨论(0)
提交回复
热议问题