PHP Countdown to Date

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

    It's not as trivial as subtracting strtotime() results, since there are daylight savings and time would be mathematically correct, but not physically. Anyway, for these purposes you should use gmdate() function, which has no daylight savings:

    $date = gmdate('U', strtotime('2009-12-03 14:00'));
    
    // Get difference between both dates without DST
    $diff = $date - gmdate('U');
    // Days (in last day it will be zero)
    $diff_days = floor($remaining / (24 * 60 * 60));
    // Hours (in the last hour will be zero)
    $diff_hours = floor($remaining % (24 * 60 * 60) / 3600);
    

提交回复
热议问题