php - Time remaining until specific time from current time of page load(php - 从当前页面加载时间到特定时间的剩余时间)
问题描述
我不得不承认,我什至没有尝试自己编写这个问题,这个问题对某些人来说可能很烦人,但我很惊讶我无法在网上找到我正在尝试的好例子去做.也许我只是没有在搜索中使用正确的关键词.
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 the web of what I'm trying to do. Perhaps I'm just not using the right key words in my searches.
我正在尝试计算从现在(页面加载的时间)到特定日期和时间(例如,2011 年 5 月 11 日星期三下午 12:00)的剩余时间并显示它.我原以为找到一个片段来实现这一点很容易,但到目前为止还没有运气.有没有人有一些他们以前用来完成这个的示例代码?我不希望有人从头开始为我写这篇文章,但如果我至少能指出正确的方向,那将非常有帮助.
I am trying to calculate the time remaining from now (the time the page loads) until a specific date and time (let's say Wednesday May 11, 2011 12:00PM for example) and display it. I had thought it would be quite easy to find a snippet to accomplish this but no luck so far. Does anyone have some example code they have used to accomplish this before? I don't expect anyone to write this for me from scratch but if I can at least get pointed in the right direction it would be extremely helpful.
推荐答案
我会使用 DateInterval 和 DateTime 函数:
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");
您需要至少 5.3 的 PHP 版本才能这样做 - 否则,请执行 helloandre 推荐.
You'll need a version of PHP that's at least 5.3 to do it this way - otherwise, do what helloandre recommends.
这篇关于php - 从当前页面加载时间到特定时间的剩余时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php - 从当前页面加载时间到特定时间的剩余时间
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01