为什么Outlook和Mac日历中的以下startTime
和endTime
没有按照下面的确切时间插入?
输入:
$timezone = 'Europe/Luxembourg';
$startTime = "2016-11-03 18:00:00";
$endTime = "2016-11-03 19:00:00";
iCalender.ics:
$icalender_for_outlook_n_osx =
'BEGIN:VCALENDAR' . "\r\n" .
'VERSION:2.0'. "\r\n" .
'PRODID:-//hacksw/handcal//NONSGML v1.0//EN'.
'BEGIN:VEVENT'. "\r\n" .
'DTEND:' . date("Ymd\THis", strtotime($endTime)) . "\r\n" .
'UID:'. uniqid() . "@".$domain . "\r\n".
'DTSTAMP:'. time() . "\r\n".
'LOCATION:' . $location . "\r\n".
'DESCRIPTION:'. $uri . "\r\n" .
'URL;VALUE=URI:' . $uri . "\r\n" .
'SUMMARY:'. $subject . "\r\n" .
'DTSTART:'. date("Ymd\THis", strtotime($startTime)) . "\r\n" .
'PRIORITY:5'. "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
Outlook或在Mac日历中,开始和结束时间要么向后或向前显示几个小时,要么永远不会获得我嵌入的值。你如何准确地将PHP时区和开始/日期时间与上面的输入提交完全相同?
答案 0 :(得分:1)
我坚信应该避免使用strtotime()
并从格式创建日期时间。
$format = 'Y-m-d H:i:s';
$icalformat = 'Ymd\THis';
$startTime = '2016-11-03 18:00:00';
$endTime = '2016-11-03 19:00:00';
echo DateTime::createFromFormat($format, $startTime)->format($icalformat); // 20161103T180000
echo DateTime::createFromFormat($format, $endTime)->format($icalformat); // 20161103T190000