本文介绍了PHP倒计时至今的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中设置日期并倒计时?例如,如果我将日期设置为12月3日下午2点,它将告诉我还剩下多少天和几小时.

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 user inputs for the date as it will be hard coded.

谢谢.

推荐答案

您可以使用strtotime函数获取指定日期的时间,然后使用时间获取时差.

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将是剩余的秒数.然后,您可以将该数字除以得到天数,小时数,分钟数等.

$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";

这篇关于PHP倒计时至今的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:30