Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP在xx天/小时和xx分钟内开始_Php - Fatal编程技术网

使用PHP在xx天/小时和xx分钟内开始

使用PHP在xx天/小时和xx分钟内开始,php,Php,我找到了很多解决方案,可以在xx天、xx小时和分钟前显示时间戳,但在将来看不到任何东西 我想输出: Starting in 2 days, 5 hours and 22 minutes 来自此unix时间戳:1331596800 $timestamp = new DateTime(); $timestamp->setTimestamp(1331596800); $diff = $timestamp->diff(new DateTime()); re

我找到了很多解决方案,可以在xx天、xx小时和分钟前显示时间戳,但在将来看不到任何东西

我想输出:

Starting in 2 days, 5 hours and 22 minutes
来自此unix时间戳:1331596800

    $timestamp = new DateTime();
    $timestamp->setTimestamp(1331596800);
    $diff = $timestamp->diff(new DateTime());

    return $diff->format('%h hours, %i minutes');
是我发现的干净简单的东西,但它没有显示正确的小时/分钟


我怎样才能做到这一点呢?

对于PHP倒数计时器,请查看SO
如果您有兴趣使用jQuery,这里有一些很好的文档。



对于PHP倒计时计时器,请查看SO
如果您有兴趣使用jQuery,这里有一些很好的文档。


试试看

$timestamp=1331596800-time();
$string=“起始于“.date($d',$timestamp)。”天“,.date($h',$timestamp)。”小时和“.date($m',$timestamp)。”分钟“;
echo$字符串

试试看

$timestamp=1331596800-time();
$string=“起始于“.date($d',$timestamp)。”天“,.date($h',$timestamp)。”小时和“.date($m',$timestamp)。”分钟“;

echo$字符串

这是我的一个应用程序中的一段代码:

    date_default_timezone_set('Asia/Calcutta'); // set the TimeZone. I am from India.

$today_date = new DateTime('now');  // now
$final_date = new DateTime('2012-03-22 09:00'); // a date in the future
$interval = $today_date->diff($final_date); // find the difference

$time_left = $interval->format('%D days, %H hours, %I minutes, %S seconds'); // display it

这只是一个例子。我希望您能够从评论中理解它。

这是我的一个应用程序中的一段代码:

    date_default_timezone_set('Asia/Calcutta'); // set the TimeZone. I am from India.

$today_date = new DateTime('now');  // now
$final_date = new DateTime('2012-03-22 09:00'); // a date in the future
$interval = $today_date->diff($final_date); // find the difference

$time_left = $interval->format('%D days, %H hours, %I minutes, %S seconds'); // display it

这只是一个例子。我希望您能从评论中理解。

您的日期格式错误。查看mroe信息。您的日期格式错误。查看mroe信息。DateTime只是@danp:是的,上面的一个需要PHP5.3才能工作。对不起,我没有这部分:
。。只是啊,那是一颗心,表示我爱这个功能:)或者♥;如果这也是你的事情(就像广告中一样!),我在挑选东西方面很慢:D谢谢你的澄清。:)谢谢你的回答。你知道如果还剩0天,我如何隐藏%D天吗?DateTime只是@danp:是的,上面的一个需要PHP5.3才能工作。对不起,我没有这部分:
。。只是啊,那是一颗心,表示我爱这个功能:)或者♥;如果这也是你的事情(就像广告中一样!),我在挑选东西方面很慢:D谢谢你的澄清。:)谢谢你的回答。如果还剩0天,您知道如何隐藏%D天吗?