2013-10-28 177 views
-1

XML文件;计算两个时间戳之间的时间量

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

“开始” &“停止”(XML格式)应该怎样做才能计算时钟之间的时间差?

例如:随着时间的计算数据

Title: hello.. 
Time:left 24 minutes 

xml文件,怎么可以做什么?

回答

0
$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

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

+0

PHP是不是在XML数据文件.. XML文件在这里:http://tvprofil.net/xmltv/data/ cnn.info/weekly_cnn.info_tvprofil.net.xml – bitmez4

+0

然后,你会使用simplexml_load_file而不是字符串... –