1

我正在创建 google vcalender ICS 文件并使用 PHP 通过电子邮件发送。

但我面临的问题是时间没有在谷歌日历上正确显示。在我的示例中,我已经通过时间为上午 01:00:00(IST),但是当我导入显示 12am(IST)的 ics 文件日历时。

当我将我的谷歌日历设置时区更改为美国(EST)时,它显示时间为下午 1:30(EST),但它应该是下午 2:30(EST)。

我的代码有什么问题?

这是我生成 ics 文件并作为电子邮件发送的 PHP 代码:

$user_timezone = dynamic timezone; // my timezone = Asia/Kolkata
    $demo_date = 2014-12-05;
    $demo_time = 01:00:00 AM;

    $meeting_date = $demo_date .' '.$demo_time;

    date_default_timezone_set($user_timezone);

    $date = date('Y-m-d H:i:s A', strtotime($meeting_date));

    // Event time stamp
    $timestamp = strtotime(date($meeting_date));

    // Event start date and end date
    $start_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);
    $end_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);

    //calender unique ID
    $cal_uid = date('Ymd').'T'.date('His')."-".rand();

    //Message send to Calender
    $ical = "BEGIN:VCALENDAR\n";
    $ical .= "VERSION:2.0\n";
    $ical .= "PRODID:-//Forest//Forest Inquiry v1.0//EN\n";
    $ical .= "CALSCALE:GREGORIAN\n";
    $ical .= "METHOD:PUBLISH\n";
    $ical .= "X-WR-CALNAME:Forest Inquiry\n";
    $ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
    $ical .= "BEGIN:VTIMEZONE\n";
    $ical .= "X-WR-TIMEZONE:{$user_timezone}\n";
    $ical .= "TZID:{$user_timezone}\n";
    $ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$user_timezone}\n";
    $ical .= "X-LIC-LOCATION:{$user_timezone}\n";
    $ical .= "END:VTIMEZONE\n";
    $ical .= "BEGIN:VEVENT\n";
    $ical .= "DTSTAMP:".date('Ymd\THis\Z')."\n";
    $ical .= "DTSTART;TZID={$user_timezone}:{$start_date}\n";
    $ical .= "DTEND;TZID={$user_timezone}:{$end_date}\n";
    $ical .= "STATUS:CONFIRMED\n";
    $ical .= "SUMMARY:{$subject}\n";
    $ical .= "DESCRIPTION:{$meeting_description}\n";
    $ical .= "ORGANIZER;CN=Forest:MAILTO:info@Forest.com\n";
    $ical .= "CLASS:PUBLIC\n";
    $ical .= "CREATED:{$start_date}Z\n";
    $ical .= "LOCATION:{$meeting_location}\n";
    $ical .= "URL:\n";
    $ical .= "SEQUENCE:1\n";
    $ical .= "LAST-MODIFIED:".date('Ymd\THis\Z')."\n";
    $ical .= "UID:{$subject}-support@mysite.com\n";
    $ical .= "END:VEVENT\n";
    $ical .= "END:VCALENDAR";

    $file_name = 'XYZ'.$first_name;
    // Mail parameters
    $newline = "\r\n";
    $headers = "From:test\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: text/calendar; charset=utf-8; name=$file_name.ics; method=REQUEST".$newline;
    $headers .= "Content-Disposition: inline; filename=$file_name.ics".$newline;
    $headers .= "Content-Transfer-Encoding: 7bit";

    mail('testing@gmail.com', $subject, $ical, $headers);

这是我的 ICS 文件:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Forest//Forest Inquiry v1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Forest Inquiry
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
TZURL:http://tzurl.org/zoneinfo-outlook/Asia/Kolkata
X-LIC-LOCATION:Asia/Kolkata
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20141205T104434Z
DTSTART;TZID=Asia/Kolkata:20141211T053000
DTEND;TZID=Asia/Kolkata:20141211T053000
STATUS:CONFIRMED
SUMMARY:Forest Inquiry by testing Testing
DESCRIPTION:First Name :testing\n
ORGANIZER;CN=Forest:MAILTO:info@Forest.com
CLASS:PUBLIC
CREATED:20141211T053000Z
LOCATION:At Forest
URL:
SEQUENCE:1
LAST-MODIFIED:20141205T104434Z
UID:Forest Inquiry by testing Testing-support@mysite.com
END:VEVENT
END:VCALENDAR
4

1 回答 1

0

查看时区 URL,您可以看到夏令时和标准时间的更正。将 IST 的 STANDARD 和 DAYLIGHT 添加到您的 vcal 中,它应该可以工作。

BEGIN:VCALENDAR
PRODID:-//tzurl.org//NONSGML Olson 2014g//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
TZURL:http://tzurl.org/zoneinfo/Asia/Kolkata
X-LIC-LOCATION:Asia/Kolkata
BEGIN:STANDARD
TZOFFSETFROM:+055328
TZOFFSETTO:+055320
TZNAME:HMT
DTSTART:18800101T000000
RDATE:18800101T000000
END:STANDARD
BEGIN:STANDARD
TZOFFSETFROM:+055320
TZOFFSETTO:+0630
TZNAME:BURT
DTSTART:19411001T000000
RDATE:19411001T000000
END:STANDARD
BEGIN:STANDARD
TZOFFSETFROM:+0630
TZOFFSETTO:+0530
TZNAME:IST
DTSTART:19420515T000000
RDATE:19420515T000000
RDATE:19451015T000000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0530
TZOFFSETTO:+0630
TZNAME:IST
DTSTART:19420901T000000
RDATE:19420901T000000
END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
于 2014-12-05T09:36:14.263 回答