php - 还剩几秒?
我试图格式化一个日期来表示还剩多少时间(以可读的格式):
<?php
$seconds = 23414;
$date = new DateTime();
$date->setTime(0, 0, $seconds);
echo $date->format('z G:i:s');
?>
这个例子可能输出类似:344 11:46:45
不是我想要的。它应该显示类似于 6 days, 4:12:36
的内容。我只是在这里没有看到任何内容: http://www.php.net/ Manual/en/function.date.php 这将帮助我正确格式化它。有想法吗?
I'm trying to format a date to say how much time is left (in a readable format) from how many seconds are left:
<?php
$seconds = 23414;
$date = new DateTime();
$date->setTime(0, 0, $seconds);
echo $date->format('z G:i:s');
?>
This example might output something like: 344 11:46:45
which is not what I'd like. It should say something like 6 days, 4:12:36
. I just don't see anything here: http://www.php.net/manual/en/function.date.php that would help me format it correctly. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道任何内置的东西,但它很容易编写:
我还没有彻底测试它,但我运行的测试运行良好。在使用它之前,您可能想自己测试一下。
I don't know of anything built in, but it's easy enough to write:
I haven't tested it thoroughly, but the tests I did run worked fine. You might want to test it yourself a bit before using it.
类似于:
很脏,但应该可以用。
Something like :
Dirty, but should work.