php - Time remaining until specific time from current time of page load

后端 未结 3 1909
梦毁少年i
梦毁少年i 2020-12-03 04:08

I have to admit that having not even tried to code this myself this question may be a annoying to some but I\'m very surprised that I wasn\'t able to find a good example on

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 04:20

    I'd use the DateInterval and DateTime functions:

    $now = new DateTime();
    $future_date = new DateTime('2011-05-11 12:00:00');
    
    $interval = $future_date->diff($now);
    
    echo $interval->format("%a days, %h hours, %i minutes, %s seconds");
    

    You'll need a version of PHP that's at least 5.3 to do it this way - otherwise, do what helloandre recommends.

提交回复
热议问题