当下面的代码在浏览器中运行时,它会显示日期和evet,如下所示:
2013-10-30T05:30:00.000-07:00 - 2013-10-30T06:30:00.000-07:00 Envent 2
2013-10-29T23:00:00.000-07:00 - 2013-10-30T00:00:00.000-07:00活动1
我希望能够将日期,时间和事件分成他们自己的可编辑ID,但我不确定如何为每个ID定位参数。
例如,它看起来更像是这样:
活动2 - 2013年10月30日,下午5:30至6:30
活动1 - 2013年10月29日,晚上11:00至凌晨12:00
守则:
$email = "yourEmail";
//your calendar has to be made public under calendar settings
$url = "http://www.google.com/calendar/feeds/".$email."/public/full";
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);
$ns=$feed->getNameSpaces(true);
foreach ($feed->entry as $entry) {
$when=$entry->children($ns["gd"]);
$when_atr=$when->when[0]->attributes();
$start=$when_atr['startTime'];
$end=$when_atr['endTime'];
$title=$entry->title;
echo "<p>".$title." ".$start." - ".$end."</p>";
}
我发现这个article很有帮助,但是,我无法弄清楚如何使其与Google日历相关。
答案 0 :(得分:1)
示例:
$start = new DateTime($when_atr['startTime']);
答案 1 :(得分:0)
经过一些研究和本线程中的帮助后,我得到了回答!
PHP
<?php
$email = "your public calendar address email";
$url = "http://www.google.com/calendar/feeds/".$email."/public/full";
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);
$ns=$feed->getNameSpaces(true);
foreach ($feed->entry as $entry) {
$when=$entry->children($ns["gd"]);
$when_atr=$when->when[0]->attributes();
$title=$entry->title;
echo "<div class='eventTitle'>".$title . "</div>";
$start = new DateTime($when_atr['startTime']);
echo "<div class='eventTime'>".$start->format('D F jS, g:ia') . " to ";
$end = new DateTime($when_atr['endTime']);
echo $end->format('g:ia')."</div>" . '<br />' ;
}
?>
CSS
<style>
.eventTime {
color:#0CF;
}
.eventTitle {
color:#0FC;
}
</style>
以下资源很有帮助:
Date,Date and Time和Example @Glavić张贴。