【发布时间】:2015-11-30 13:46:14
【问题描述】:
我正在开发一个 PHP 工具来创建一个将通过邮件发送的 ICS 文件。
创建文件后,我尝试将其添加到 Outlook 2016 或 iCalendar (Apple) 中。除开始时间和结束时间外,所有信息均正确无误。它们偏离一小时。
示例:
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Communication Maker
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTART;TZID=Europe/Zurich:20151201T150000Z
DTEND;TZID=Europe/Zurich:20151201T180000Z
UID:565c50b5ca7d9
LOCATION:Location
SUMMARY:Title
DESCRIPTION:Content
END:VEVENT
END:VCALENDAR
这是文件信息:
开始时间:01/12/2015 @ 15:00:00
结束时间:01/12/2015 @ 18:00:00
时区:UTC +01:00(欧洲/苏黎世)
这里是 Outlook 和 iCalendar 上的结果:
开始时间:01/12/2015 @ 16:00:00
结束时间:01/12/2015 @ 19:00:00
我已经搜索了 4 天,但找不到使用正确数据进行活动的答案。
如果你愿意,我可以给你更多我的代码(HTML 或 PHP 类)。
有我的课:
class ICS {
private $sSaveDir = './icsFiles/';
private $sIcsContent = '';
private $sIcsDateFormat = 'Ymd\THis\Z';
public function __construct($sTitle = null, $sLocation = null, $sUrl = null, $sTimezoneValue = null, $sEventText = null, $sDateS = null, $sTimeS = null, $sDateE = null, $sTimeE = null) {
// Timezone par défaut
date_default_timezone_set('UTC');
// Génération de l'ID unique
$sUniqId = uniqid();
// Construction du array
$aIcsContent = array(
"BEGIN:VCALENDAR",
"METHOD:PUBLISH",
"VERSION:2.0",
"PRODID:-//Communication Maker",
"CALSCALE:GREGORIAN",
"BEGIN:VEVENT",
"DTSTART;TZID=".$sTimezoneValue.":".date($this->sIcsDateFormat, strtotime($sDateS." ".$sTimeS)),
"DTEND;TZID=".$sTimezoneValue.":".date($this->sIcsDateFormat, strtotime($sDateE." ".$sTimeE)),
"UID:".$sUniqId,
"LOCATION:".$sLocation,
"SUMMARY:".$sTitle,
"DESCRIPTION:".$sEventText,
"END:VEVENT",
"END:VCALENDAR"
);
// Array => string
$this->sIcsContent = implode(PHP_EOL, $aIcsContent);
// Créer et ouvre le fichier en écriture seule
if($oIcsFile = fopen($this->sSaveDir.'event_'.$sUniqId.'.ics', 'w')) {
// Inscrit les données de l'événement dans le fichier
fwrite($oIcsFile, $this->sIcsContent);
// Ferme le fichier proprement
fclose($oIcsFile);
echo 'true';
}
else {
echo 'false';
}
}
}
感谢您的帮助。我真的需要它。
【问题讨论】: