Php 在不同时区打开时无法使vCalendar(vcs)进行时间调整

Php 在不同时区打开时无法使vCalendar(vcs)进行时间调整,php,vcalendar,Php,Vcalendar,我正在使用iCalcreator(v2.6)PHP库创建一个.vcs文件。在Outlook(最新版本,我不知道其他版本)中打开活动时,会议日期/时间不会调整为本地时间。我认为这可能与有关,但设置X-MICROSOFT-CDO-TZID值似乎没有帮助。我希望有人知道一些关于vcs文件创建谁可以告诉我在正确的方向。以下是我正在创建的vcs文件: BEGIN:VCALENDAR CALSCALE:GREGORIAN METHOD:PUBLISH PRODID:-//127.0.53.53//NONSG

我正在使用iCalcreator(v2.6)PHP库创建一个.vcs文件。在Outlook(最新版本,我不知道其他版本)中打开活动时,会议日期/时间不会调整为本地时间。我认为这可能与有关,但设置X-MICROSOFT-CDO-TZID值似乎没有帮助。我希望有人知道一些关于vcs文件创建谁可以告诉我在正确的方向。以下是我正在创建的vcs文件:

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:PUBLISH
PRODID:-//127.0.53.53//NONSGML iCalcreator 2.6//
VERSION:2.0
BEGIN:VTIMEZONE
TZID:US/Pacific
LAST-MODIFIED:20040110T032845Z
X-MICROSOFT-CDO-TZID:13
BEGIN:DAYLIGHT
DTSTART:19900404T010000
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU
TZNAME:PDT
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:19901026T060000
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
TZNAME:PST
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:20170413T205736CEST-5403Nbu2Iu@127.0.53.53
DTSTAMP:20170413T185736Z
DESCRIPTION:sdfg\n\nSome awesome description
DTSTART:20170419T180000
DURATION:PT3H0M0S
LOCATION:The best place in the world
SUMMARY:One fine summary
END:VEVENT
END:VCALENDAR

几年过去了,但这是我的工作方式,也许这会帮助其他任何遇到这个问题的人

我从来没有尝试过TZOFFSETFROM…所以不确定这是关于什么,甚至不知道它是否有效。但是,如果将时区放在DTSTART和DTEND中,它将自动调整。您只需要将日期设置为UTC格式,就像上次修改的日期一样。我这样做(
$start
$end
是PHP日期时间对象):

因此,基本上,所做的就是将日期放入UTC时区,然后在末尾用Z格式化日期/时间,以将其传达给客户机

一个完整的工作示例(如果对任何人都有帮助)是:


"DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z').$eol.
"DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z')
<?php
    date_default_timezone_set('America/New_York');
    //CONFIGURE HERE
    $fromName           = "John Doe";
    $fromEmail          = "john.doe@example.com";
    $toName             = "Your Name";
    $toEmail            = 'yourname@example.com';
    $start              = new DateTime('2017-08-15 15:00');
    $end                = new DateTime('2017-08-15 16:00');
    $summary            = "Hello World Event";
    //END CONFIGURATION

    $uid                = "0123456789";
    $headers            = array();
    $boundary           = "_CAL_" . uniqid("B",true) . "_B_";
    $headers[]          = "MIME-Version: 1.0";
    $headers[]          = "Content-Type: multipart/alternative; boundary=\"".$boundary."\"";
    $headers[]          = "To: \"{$toName}\" <{$toEmail}>";
    $headers[]          = "From: \"{$fromName}\" <{$fromEmail}>";

    $calendarLines      = array(
        "BEGIN:VCALENDAR",
        "METHOD:REQUEST",
        "PRODID:-//PHP//MeetingRequest//EN",
        "VERSION:2.0",
        "BEGIN:VEVENT",
        "ORGANIZER;CN={$fromName}:MAILTO:{$fromEmail}",
        "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={$toName}:MAILTO:{$toEmail}",
        "DESCRIPTION:{$summary}",
        "SUMMARY:{$summary}",
        "DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
        "DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
        "UID:{$uid}",
        "CLASS:PUBLIC",
        "PRIORITY:5",
        "DTSTAMP:".gmdate('Ymd\THis\Z'),
        "TRANSP:OPAQUE",
        "STATUS:CONFIRMED",
        "SEQUENCE:0",
        "LOCATION:123 Any Street",
        "BEGIN:VALARM",
        "ACTION:DISPLAY",
        "DESCRIPTION:REMINDER",
        "TRIGGER;RELATED=START:-PT15M",
        "END:VALARM",
        "END:VEVENT",
        "END:VCALENDAR"
    );


    $calendarBase64     = base64_encode(implode("\r\n",$calendarLines));
    //ensure we don't have lines longer than 70 characters for older computers:
    $calendarResult     = wordwrap($calendarBase64,68,"\n",true);

    $emailLines = array(
        "--{$boundary}",
        "Content-Type: text/html; charset=\"iso - 8859 - 1\"",
        "Content-Transfer-Encoding: quoted-printable",
        "",
        "<html><body>",
        "<h1>Hello World</h1>",
        "<p>This is a calendar event test</p>",
        "</body></html>",
        "",
        "--{$boundary}",
        "Content-Type: text/calendar; charset=\"utf - 8\"; method=REQUEST",
        "Content-Transfer-Encoding: base64",
        "",
        $calendarResult,
        "",
        "--{$boundary}--"
    );
    $emailContent   = implode("\n",$emailLines);

    $headersResult      = implode("\n",$headers);
    mail($toEmail, $summary, $emailContent, $headersResult );
    echo("<pre>".htmlentities($headersResult)."\n\n".htmlentities($emailContent)."</pre>");
    echo("<br /><br />");
    echo("<pre>".base64_decode($calendarResult)."</pre>");