通过 php 代码发送日历事件的时区


Sending TimeZone for Calendar Event through php Code

我正在使用以下代码将日历事件发送到Outlook。我面临时区问题。我将开始时间发送为晚上 8 点。但是,它设置了第二天凌晨 1:30。请检查下面的代码,并建议我如何发送时区与时间。

       <?php
    $dtStart = '20131019T131415Z';//yyyymmddThhmmssZ
    $dtEnd = '20131019T151617Z';
    //--------------------
    //create text file
    $ourFileName = "temp_files/calendar.txt";
    $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file1");
    fclose($ourFileHandle);
    //
    //edit temp file
    $myFile = "temp_files/calendar.txt";
    $fh = fopen($myFile, 'w') or die("can't open file2");
    $stringData = "
    BEGIN:VCALENDAR'n 
    PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN'n 
    VERSION:2.0'n 
    METHOD:REQUEST'n 
    BEGIN:VEVENT'n 
    ORGANIZER:MAILTO:organizer@domain.com'n 
    DTSTAMP:".date('Ymd').'T'.date('His')."'n
    DTSTART:$dtStart'n 
    DTEND:$dtEnd'n 
    TRANSP:OPAQUE'n 
    SEQUENCE:0'n 
    UID:".date('Ymd').'T'.date('His')."-".rand()."-domain.com'n 
    SUMMARY:do something someware'n 
    DESCRIPTION:  This is just a test'n
    PRIORITY:5'n 
    X-MICROSOFT-CDO-IMPORTANCE:1'n 
    CLASS:PUBLIC'n 
    END:VEVENT'n 
    END:VCALENDAR";
    fwrite($fh, $stringData);
    fclose($fh);

//email temp file
$fileatt = "temp_files/calendar.txt"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "ical.ics"; // Filename that will be used for the file as the attachment
$email_from = "fromPerson@domain.com"; // Who the email is from
$email_subject = "Email test"; // The Subject of the email
$email_message = "this is a sample message 'n'n next line 'n'n next line"; // Message that the email has in it
$email_to = "toPerson@domain.com"; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "'nMIME-Version: 1.0'n" .
"Content-Type: multipart/mixed;'n" .
" boundary='"{$mime_boundary}'"";
$email_message .= "This is a multi-part message in MIME format.'n'n" .
"--{$mime_boundary}'n" .
"Content-Type:text/html; charset='"iso-8859-1'"'n" .
"Content-Transfer-Encoding: 7bit'n'n" .
$email_message . "'n'n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}'n" .
"Content-Type: {$fileatt_type};'n" .
" name='"{$fileatt_name}'"'n" .
//"Content-Disposition: attachment;'n" .
//" filename='"{$fileatt_name}'"'n" .
"Content-Transfer-Encoding: base64'n'n" .
$data . "'n'n" .
"--{$mime_boundary}--'n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
} 

?>

RFC 5545 中有很多关于时区的信息。

例子:

DTSTART;TZID=America/New_York:19980119T020000
DTEND;TZID=America/New_York:19980119T030000
TZID=America/New_York:19980119T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
BEGIN:VTIMEZONE
TZID:America/New_York
LAST-MODIFIED:20050809T050000Z
BEGIN:STANDARD
DTSTART:20071104T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
END:VTIMEZONE