Chinaunix

标题: 奇怪的问题 [打印本页]

作者: ld1978    时间: 2012-12-18 11:23
标题: 奇怪的问题
练习的程序如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>计算离元旦还有多长时间</title>
</head>

<body>
<?php
function run_time(){
        list($msec,$sec) = explode(" ",microtime());
        return ((float)$msec + (float)$sec);
}
        $start_time = run_time();
        $time1 = strtotime(date("Y-m-d H:i:s"));
        $time2 = strtotime("2012-2-8 16:30:00");
        $time3 = strtotime("2013-1-1");
        $sub1 = ceil(($time2 - $time1) / 3600);
        $sub2 = ceil(($time3 - $time1) /86400);
        echo "离放假还有<font color=red> $sub1 </font>小时!!!";
        echo "<p>";
        echo "离2013年元旦还有<font color=red>$sub2</font>天!!!";
        echo "<p>";
        $end_time = run_time();
        //$runtime=$end_time-$start_time;
        //echo $runtime;
?>       
<font color=blue><?php echo"程序运行时间为:".($end_time-$start_time);?></font>秒
</body>
</html>

为什么在网页中输出的是这样的情况呢?

离放假还有 -7530 小时!!!
离2013年元旦还有14天!!!

程序运行时间为:6.5088272094727E-5
如标红的部分,而不是计算的结果呢?
作者: ld1978    时间: 2012-12-18 11:25
哦,我理解错了。。。不好意思。这个是结果。
作者: maochanglu    时间: 2012-12-19 10:53
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>计算离元旦还有多长时间</title>
  6. </head>

  7. <body>
  8. <?php
  9. function run_time(){
  10.         list($msec,$sec) = explode(" ",microtime());
  11.         return ((float)$msec + (float)$sec);
  12. }
  13.         $start_time = run_time();
  14.         $time1 = strtotime(date("Y-m-d H:i:s"));
  15.         $time2 = strtotime("2012-2-8 16:30:00");
  16.         $time3 = strtotime("2013-1-1");
  17.         $sub1 = ceil(($time2 - $time1) / 3600);
  18.         $sub2 = ceil(($time3 - $time1) /86400);
  19.         echo "离放假还有<font color=red> $sub1 </font>小时!!!";
  20.         echo "<p>";
  21.         echo "离2013年元旦还有<font color=red>$sub2</font>天!!!";
  22.         echo "<p>";
  23.         $end_time = run_time();
  24.         //$runtime=$end_time-$start_time;
  25.         //echo $runtime;
  26. ?>        
  27. <font color=blue><?php echo"程序运行时间为:".($end_time-$start_time);?></font>秒
  28. </body>
  29. </html>
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2