Php ICS文件中的错误时间
我正在开发一个PHP工具来创建将通过邮件发送的ICS文件 创建文件后,我尝试将其添加到Outlook 2016或iCalendar(Apple)中。除开始时间和结束时间外,所有信息均正确。它们从一个小时开始偏移 埃克斯姆莱:Php ICS文件中的错误时间,php,outlook,icalendar,Php,Outlook,Icalendar,我正在开发一个PHP工具来创建将通过邮件发送的ICS文件 创建文件后,我尝试将其添加到Outlook 2016或iCalendar(Apple)中。除开始时间和结束时间外,所有信息均正确。它们从一个小时开始偏移 埃克斯姆莱: BEGIN:VCALENDAR METHOD:PUBLISH VERSION:2.0 PRODID:-//Communication Maker CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;TZID=Europe/Zurich:20151
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
以下是文件信息:
开始时间:2015年12月1日15:00:00
结束时间:2015年12月1日18:00:00
时区:UTC+01:00(欧洲/苏黎世)
下面是Outlook和iCalendar的结果:
开始时间:2015年12月1日16:00:00
结束时间:2015年12月1日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';
}
}
}
谢谢你的帮助。我真的需要它。你的ICS文件上说时间是2015年12月1日UTC时区15:00:00。上面写着用苏黎世时间显示时间。苏黎世是UTC+100,因此将时间显示为2015年12月1日苏黎世时间16:00:00(中欧时间)是正确的
20151201T150000Z
末尾的Z
表示“祖鲁时间”,它(大致)是UTC时间的另一个名称
要使事件开始的日期/时间指定为苏黎世时间,而不是UTC,只需从时间中删除Z
,如下所示:20151201T150000
如果希望坐在UTC+100的人看到15:00,而坐在UTC+200的人看到16:00作为时间,则应指定UTC时间。在这种情况下,您可以将时间设置为
20151201T140000Z
,因为这是2015年12月1日15:00:00 UTC+100的UTC等效时间。是的,但我想显示UTC+01:00的15:00。如果使用UTC+02:00的日历打开日历,您将看到16:00。您是说您希望UTC+200中的人看到16:00,而UTC+100中的人看到15:00?是的,这正是我想要的。如果我将日期转换为时区会怎么样?类似于:date($this->sIcsDateFormat,strotime($sDateS.”“$sTimeS.”“$sTimezoneValue”)
我建议将时间转换为UTC。