我试图在PHP中动态生成ics文件,其中时区根据给定的位置是动态的。一切都很好,但有一个夏令时问题,即它显示一个小时左右的时差。现在为了解决这个问题,我必须动态地使用DAYLIGHT
。但是我不知道如何动态地使用它,或者从哪里可以得到与给定时区相关的TZOFFSETFROM
和TZOFFSETTO
偏移量。
$timeZone = "America/Denver" // dynamically fetched from DB
$ical = "BEGIN:VCALENDARn";
$ical .= "VERSION:2.0n";
$ical .= "PRODID:-//LokalMotion//LokalMotion Events v1.0//ENn";
$ical .= "CALSCALE:GREGORIANn";
$ical .= "METHOD:PUBLISHn";
$ical .= "X-WR-CALNAME:LokalMotion Eventsn";
$ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUEn";
$ical .= "BEGIN:VTIMEZONEn";
$ical .= "TZID:{$timeZone}n";
$ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$timeZone}n";
$ical .= "X-LIC-LOCATION:{$timeZone}n";
$ical .= "END:VTIMEZONEn";
$ical .= "BEGIN:VEVENTn";
$ical .= "DTSTAMP:".date('YmdTHisZ')."n";
$ical .= "DTSTART;TZID={$timeZone}:{$start_date}n";
$ical .= "DTEND;TZID={$timeZone}:{$end_date}n";
$ical .= "STATUS:CONFIRMEDn";
$ical .= "SUMMARY:{$title}n";
$ical .= "DESCRIPTION:{$description}n";
$ical .= "ORGANIZER;CN=Reminder:MAILTO:support@mysite.comn";
$ical .= "CLASS:PUBLICn";
$ical .= "CREATED:{$start_date}Zn";
$ical .= "LOCATION:{$location}n";
$ical .= "URL:http://www.mysite.comn";
$ical .= "SEQUENCE:1n";
$ical .= "LAST-MODIFIED:".date('YmdTHisZ')."n";
$ical .= "UID:{$title}-support@mysite.comn";
$ical .= "END:VEVENTn";
$ical .= "END:VCALENDAR";
echo $ical;
现在如何根据位置动态使用日光,比如位置可以是'America/Caracas' ..等
$ical .= "BEGIN:DAYLIGHT";
$ical .= "TZOFFSETFROM:{}"; //I need this dynamic
$ical .= "TZOFFSETTO:{}";//I need this dynamic
$ical .= "TZNAME:EDT";
$ical .= "DTSTART;TZID={$timeZone}:{$start_date}n";
$ical .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU";
$ical .= "END:DAYLIGHT";
在转换时间和日期之前,您应该在PHP中设置正确的时区,以便引擎知道您正在使用的时区的时间特征:
date_default_timezone_set('America/Mexico_City');
$start_date = date('c', time()); // ISO date 8601 of "right now"
$start_zone = date('O', time()); // TZOFFSETFROM format of "right now"
date_default_timezone_set('America/Denver');
$to_zone = date('O', time()); // TZOFFSETTO of "right now"
希望能有所帮助