谷歌日历显示错误的时间

时间:2014-12-05 07:17:10

标签: php vcalendar

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

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

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

我的代码出了什么问题?

这是我生成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

1 个答案:

答案 0 :(得分:0)

查看时区网址,您可以看到日光和标准时间的更正。为你添加STSTARD和DAYLIGHT for IST,它应该可以工作。

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