如何格式化 ical 和 outlook 日历的日期时间
how to format date time for ical and outlook calendar
我正在尝试将事件添加到 google、outlook 和 ical 日历。将事件添加到 google 日历工作正常,但对于 outlook 和 ical,时间上存在一些问题。
当我将开始时间添加为 1:00 pm 并将结束时间添加为 12:00 am 时,对于同一日期,ical 生成的结束时间为 12:00 am,结束时间为 1:00 pm。我正在生成 ical,如下所示。我不知道我做错了什么?任何 help/suggestions 表示赞赏。
$startDate = $_GET['startDate'];
$startTime = $_GET['startTime'];
$startDateTime = $startDate . ' ' . $startTime; //2020-10-08 13:00:00
$endDate = $_GET['endDate'];
$endTime = $_GET['endTime'];
$endDateTime = $endDate . ' ' . $endTime; //2020-10-08 00:00:00
$subject = $_GET['subject'];
$desc = $_GET['desc'];
$location = $_GET['location'];
$filename = $subject . '.ics';
$format = 'Y-m-d H:i:s';
$icalformat = 'Ymd\THis';
$startDateTime = DateTime::createFromFormat($format, $startDateTime);
$startDateTime = $startDateTime->format( $icalformat );
$endDateTime = DateTime::createFromFormat( $format, $endDateTime );
$endDateTime = $endDateTime->format( $icalformat );
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5( uniqid( mt_rand(), true ) ) . "example.com
DTSTAMP:" . gmdate('Ymd') . 'T' . gmdate( 'His' ) . "
DTSTART:" . $startDateTime . "
DTEND:" . $endDateTime . "
LOCATION:" . $location . "
SUMMARY:" . $subject . "
DESCRIPTION:" . $desc . "
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header( 'Content-type: text/calendar; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=' . $filename );
echo $ical;
exit;
结束时间怎么能早于开始时间呢?不应该是第二天的午夜吗? 2020-10-09 00:00:00.
我正在尝试将事件添加到 google、outlook 和 ical 日历。将事件添加到 google 日历工作正常,但对于 outlook 和 ical,时间上存在一些问题。 当我将开始时间添加为 1:00 pm 并将结束时间添加为 12:00 am 时,对于同一日期,ical 生成的结束时间为 12:00 am,结束时间为 1:00 pm。我正在生成 ical,如下所示。我不知道我做错了什么?任何 help/suggestions 表示赞赏。
$startDate = $_GET['startDate'];
$startTime = $_GET['startTime'];
$startDateTime = $startDate . ' ' . $startTime; //2020-10-08 13:00:00
$endDate = $_GET['endDate'];
$endTime = $_GET['endTime'];
$endDateTime = $endDate . ' ' . $endTime; //2020-10-08 00:00:00
$subject = $_GET['subject'];
$desc = $_GET['desc'];
$location = $_GET['location'];
$filename = $subject . '.ics';
$format = 'Y-m-d H:i:s';
$icalformat = 'Ymd\THis';
$startDateTime = DateTime::createFromFormat($format, $startDateTime);
$startDateTime = $startDateTime->format( $icalformat );
$endDateTime = DateTime::createFromFormat( $format, $endDateTime );
$endDateTime = $endDateTime->format( $icalformat );
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5( uniqid( mt_rand(), true ) ) . "example.com
DTSTAMP:" . gmdate('Ymd') . 'T' . gmdate( 'His' ) . "
DTSTART:" . $startDateTime . "
DTEND:" . $endDateTime . "
LOCATION:" . $location . "
SUMMARY:" . $subject . "
DESCRIPTION:" . $desc . "
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header( 'Content-type: text/calendar; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=' . $filename );
echo $ical;
exit;
结束时间怎么能早于开始时间呢?不应该是第二天的午夜吗? 2020-10-09 00:00:00.