dtcwehta624485 2013-05-14 13:18
浏览 93
已采纳

ICS文件动态时区问题[重复]

This question already has an answer here:

I am trying to generate ics file dynamically in PHP, where timezone is dynamic according to the location given. Everything works good but there is daylight time issue i.e it shows time difference of one hour or so. Now to solve this issue I have to use DAYLIGHT dynamically. but I don't know how to use it dynamically, or where from can I get TZOFFSETFROM and TZOFFSETTO offsets related with timezone given.

For Example:

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

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

echo $ical;

Now how to use daylight dynamically according to the location, like location can be 'America/Caracas' .. etc

$ical .= "BEGIN:DAYLIGHT";
$ical .= "TZOFFSETFROM:{}"; //I need this dynamic
$ical .= "TZOFFSETTO:{}";//I need this dynamic
$ical .= "TZNAME:EDT";
$ical .= "DTSTART;TZID={$timeZone}:{$start_date}
";
$ical .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU";
$ical .= "END:DAYLIGHT";

Thanks in advance.

</div>
  • 写回答

2条回答 默认 最新

  • duande8497 2013-05-14 13:35
    关注

    Before converting times and date, you should set the correct timezone in PHP so the engine knows the time characteristics of the zone you are using:

    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"
    

    Hope this may help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译