0

我正在尝试在 PHP 中动态生成 ics 文件,其中时区根据给定的位置是动态的。一切正常,但存在日光时间问题​​,即它显示一小时左右的时差。现在要解决这个问题,我必须DAYLIGHT动态使用。但我不知道如何动态使用它,或者我可以从哪里获得TZOFFSETFROMTZOFFSETTO给定时区相关的偏移量。

例如:

    $timeZone = "America/Denver" // dynamically fetched from DB

      $ical = "BEGIN:VCALENDAR\n";
      $ical .= "VERSION:2.0\n";
      $ical .= "PRODID:-//LokalMotion//LokalMotion Events v1.0//EN\n";
      $ical .= "CALSCALE:GREGORIAN\n";
      $ical .= "METHOD:PUBLISH\n";
      $ical .= "X-WR-CALNAME:LokalMotion Events\n";
      $ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
      $ical .= "BEGIN:VTIMEZONE\n";
      $ical .= "TZID:{$timeZone}\n";
      $ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$timeZone}\n";
      $ical .= "X-LIC-LOCATION:{$timeZone}\n";
      $ical .= "END:VTIMEZONE\n";
      $ical .= "BEGIN:VEVENT\n";
      $ical .= "DTSTAMP:".date('Ymd\THis\Z')."\n";
      $ical .= "DTSTART;TZID={$timeZone}:{$start_date}\n";
      $ical .= "DTEND;TZID={$timeZone}:{$end_date}\n";
      $ical .= "STATUS:CONFIRMED\n";
      $ical .= "SUMMARY:{$title}\n";
      $ical .= "DESCRIPTION:{$description}\n";
      $ical .= "ORGANIZER;CN=Reminder:MAILTO:support@mysite.com\n";
      $ical .= "CLASS:PUBLIC\n";
      $ical .= "CREATED:{$start_date}Z\n";
      $ical .= "LOCATION:{$location}\n";
      $ical .= "URL:http://www.mysite.com\n";
      $ical .= "SEQUENCE:1\n";
      $ical .= "LAST-MODIFIED:".date('Ymd\THis\Z')."\n";
      $ical .= "UID:{$title}-support@mysite.com\n";
      $ical .= "END:VEVENT\n";
      $ical .= "END:VCALENDAR";    

echo $ical;

现在如何根据位置动态使用日光,例如位置可以是“美国/加拉加斯”......等

$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";

提前致谢。

4

1 回答 1

-1

在转换时间和日期之前,您应该在 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"

希望这可能会有所帮助

于 2013-05-14T13:35:45.197 回答