从Oulook导出.ics文件在不同时区出现日期时间

时间:2016-04-05 10:12:50

标签: php icalendar

我在我的项目中使用icalendar。在我的应用程序中有一些特权,用户可以生成并导出.ics文件并导入到outlook中。在outlook中,用户可以添加一些事件,也可以生成.ics文件并导入日历。问题是当用户导出.ics文件然后文件包含以下数据时:

  "start_datetime" => "2016-04-06 18:00:00" //UTC Time
  "end_datetime" => "2016-04-06 18:30:00"   //UTC Time
  "status" => null
  "title" => "Free"
  "description" => ""
  "from" => "Dr Demo xprt02"

当用户将该文件导入outlook时,再次从outlook导出并导回到应用程序,然后.ics返回:

    array:11 [▼
        "CLASS" => "PUBLIC"
        "CREATED" => "20160405T073709Z"
        "DTEND" => "20160406T130000Z"
        "DTSTAMP" => "20160405T020700Z"
        "DTSTART" => "20160406T123000Z"
        "LAST-MODIFIED" => "20160405T073709Z"
        "SEQUENCE" => "0"
        "SUMMARY" => " Free"
        "TRANSP" => "OPAQUE"
        "UID" => "20160405T073649-31540-f4wd.com"
        "X-MICROSOFT-CDO-BUSYSTATUS" => "BUSY"
    ]

将.ics内容转换为php后我得到了。

  "start_datetime" => "2016-04-06 12:30:00"
  "end_datetime" => "2016-04-06 13:00:00" 
  "status" => null
  "title" => "Free"
  "description" => ""
  "from" => "Dr Demo xprt02"

我不知道为什么在从outlook获取相同文件后startdatetimeend_datetime存在这样的差异。我认为展望未在UTC中回归。如果有人有任何想法,请分享。

1 个答案:

答案 0 :(得分:-1)

我得到了答案。

$ics =  "BEGIN:VCALENDAR\n";
$ics .= "PRODID:-//F4WD TM//NONSGML F4WD//EN\n";
$ics .= "VERSION:2.0\n";
$ics .= "CALSCALE:GREGORIAN\n";
$ics .= "METHOD:PUBLISH\n"; // requied by Outlook
$ics .= "X-WR-CALNAME:\n";
$ics .= "TZ:+00:\n";
$ics .= "BEGIN:VEVENT\n";
$ics .= "CLASS:PUBLIC\n";
$ics .= "CREATED:".date('Ymd', strtotime($v['start_datetime'])).'T'.date('His', strtotime($v['start_datetime']))."Z\n"; 
$ics .= "DTEND;TZID=UTC:".date('Ymd', strtotime($v['end_datetime'])).'T'.date('His', strtotime($v['end_datetime']))."Z\n"; 
$ics .= "DTSTAMP:".date('Ymd').'T'.date('His')."Z\n"; 
$ics .= "DTSTART;TZID=UTC:".date('Ymd', strtotime($v['start_datetime'])).'T'.date('His', strtotime($v['start_datetime']))."\n";
$ics .= "LAST-MODIFIED:".date('Ymd', strtotime($v['start_datetime'])).'T'.date('His', strtotime($v['start_datetime']))."\n"; 
$ics .= "SEQUENCE: 0\n";
$ics .= "SUMMARY: ".$v['title']. "\n";
$ics .= "TRANSP:OPAQUE \n";
$ics .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-".$domain_url."\n"; 
$ics .= "DESCRIPTION:".$v['description']."\n";
$ics .= "X-MICROSOFT-CDO-BUSYSTATUS:BUSY".$v['status']."\n";
$ics .= "END:VEVENT\n";
$ics .= "END:VCALENDAR\n";

我没有将; TZID = UTC DTSTART DTEND 一起使用。所以现在一切正常。