【问题标题】:Calculating the amount of time between the two timestamps [closed]计算两个时间戳之间的时间量[关闭]
【发布时间】:2014-03-01 23:17:20
【问题描述】:

XML 文件;

 <programme channel="cnn.info" start="20131027060000" stop="20131027061500">
 <title>hello CONTENT</title>
 <premiere/></programme>

“开始”和“停止”(在xml中)应该做计算时钟之间的时间差吗?

例如:

Title: hello.. 
Time:left 24 minutes

xml文件中的数据在计算的时候,怎么办?

【问题讨论】:

    标签: php xml


    【解决方案1】:

    应该瞄准这样的事情:

    $string = <<<XML
     <programme channel="cnn.info" start="20131027060000" stop="20131027061500">
     <title>hello CONTENT</title>
     <premiere/></programme>
    XML;
    
    $xml = simplexml_load_string($string);
    
    $start = $xml->attributes()->start;
    $stop = $xml->attributes()->stop;
    $title = $xml->title;
    $datetime1 = new DateTime($start);
    $datetime2 = new DateTime($stop);
    $interval = $datetime1->diff($datetime2);
    echo "Title: " . $title . "\n";
    echo $interval->format('Time left: %i minutes');
    

    输出:

    Title: hello CONTENT
    Time left: 15 minutes
    

    http://3v4l.org/gDPTQ

    【讨论】:

    【解决方案2】:
    $xml = simplexml_load_file("filename.xml");
    
    echo $xml->programme->title . "<br />";
    echo "Time: left" . $time_left;
    

    $time_left 将是停止日期减去开始日期,然后将其转换为 php 日期。

    另请阅读此主题: Php get how many days and hours left from a date

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      相关资源
      最近更新 更多