【问题标题】:ICAL Wrong date in outlook (windows and android) but good in Google Calendar and Iphone icalICAL Outlook(windows 和 android)中的日期错误,但在 Google 日历和 Iphone ical 中很好
【发布时间】:2017-11-09 18:30:21
【问题描述】:

嗨,我正忙着处理一个日历。 但他显示错误的日期:

BEGIN:VEVENT
SUMMARY:TEST EVENT!
UID:140
STATUS:CONFIRMED
DTSTAMP;TZID=Europe/Amsterdam:20170610T220000Z
DTSTART;TZID=Europe/Amsterdam:20170610T220000Z
DTEND;TZID=Europe/Amsterdam:20170610T220000Z
LAST-MODIFIED:20170608T064314Z
LOCATION:STREET 1 1111 AA CITY
END:VEVENT
END:VCALENDAR

这应该是日期:11/06/2017 22:00(阿姆斯特丹白天) 在 Outlook 中是日期:11/06/2017 00:00(阿姆斯特丹白天)

这是我的其余代码:

BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//2017/TEST CALENDAR//EN
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
BEGIN:STANDARD
DTSTART:20151025T020000
RDATE:20160327T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:Europe/Amsterdam CET
END:STANDARD
BEGIN:STANDARD
DTSTART:20161030T020000
RDATE:20170326T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:Europe/Amsterdam CET
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20150601T073000
RDATE:20151025T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:Europe/Amsterdam CEST
END:DAYLIGHT
BEGIN:DAYLIGHT
DTSTART:20160327T030000
RDATE:20161030T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:Europe/Amsterdam CEST
END:DAYLIGHT

希望有人能帮帮我! 非常感谢!

我生成 Ical 的 php 代码如下:

<?php
date_default_timezone_set('Europe/Amsterdam');
$querystr ="
SELECT $wpdb->posts.* 
FROM $wpdb->posts, $wpdb->postmeta 
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
AND ( $wpdb->posts.post_status = 'confirmed'
OR $wpdb->posts.post_status = 'pending'
)
ORDER BY $wpdb->posts.post_date DESC";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=TESTAGENDA.ics");
// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\THis\Z');
// max line length is 75 chars. New line is \\n
$output = "BEGIN:VCALENDAR\r\n";
$output .= "METHOD:PUBLISH\r\n";
$output .= "VERSION:2.0\r\n";
$output .= "PRODID:-//2017/TEST AGENDA//EN\r\n";

$output .= "BEGIN:VTIMEZONE\r\n";
$output .= "TZID:Europe/Amsterdam\r\n";
$output .= "BEGIN:STANDARD\r\n";
$output .= "DTSTART:20151025T020000\r\n";
$output .= "RDATE:20160327T030000\r\n";
$output .= "TZOFFSETFROM:+0200\r\n";
$output .= "TZOFFSETTO:+0100\r\n";
$output .= "TZNAME:Europe/Amsterdam CET\r\n";
$output .= "END:STANDARD\r\n";
$output .= "BEGIN:STANDARD\r\n";
$output .= "DTSTART:20161030T020000\r\n";
$output .= "RDATE:20170326T030000\r\n";
$output .= "TZOFFSETFROM:+0200\r\n";
$output .= "TZOFFSETTO:+0100\r\n";
$output .= "TZNAME:Europe/Amsterdam CET\r\n";
$output .= "END:STANDARD\r\n";
$output .= "BEGIN:DAYLIGHT\r\n";
$output .= "DTSTART:20150601T073000\r\n";
$output .= "RDATE:20151025T020000\r\n";
$output .= "TZOFFSETFROM:+0100\r\n";
$output .= "TZOFFSETTO:+0200\r\n";
$output .= "TZNAME:Europe/Amsterdam CEST\r\n";
$output .= "END:DAYLIGHT\r\n";
$output .= "BEGIN:DAYLIGHT\r\n";
$output .= "DTSTART:20160327T030000\r\n";
$output .= "RDATE:20161030T020000\r\n";
$output .= "TZOFFSETFROM:+0100\r\n";
$output .= "TZOFFSETTO:+0200\r\n";
$output .= "TZNAME:Europe/Amsterdam CEST\r\n";
$output .= "END:DAYLIGHT\r\n";
$output .= "END:VTIMEZONE\r\n";
?>
<?php if ($pageposts){ ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php $postmeta_reservering = get_post_meta( get_the_ID(), 'rtb', true );
if ( ! empty( $postmeta_reservering ) ) {
    $aantalpersonen = $postmeta_reservering['party'];
    $emailadres = $postmeta_reservering['email'];
    $telefoonnr = $postmeta_reservering['phone'];
    $ipadres = $postmeta_reservering['ip'];
}
?>
<?php setup_postdata($post); ?>
<?php if($post->post_status == 'confirmed'){$poststatus = 'CONFIRMED';}else{$poststatus = 'IN-PROCESS';}
$output .= "BEGIN:VEVENT\r\n";
$output .= "SUMMARY:".$post->post_title." Tel.:".$telefoonnr." (".$aantalpersonen." pers.)\r\n";
$output .= "UID:".$post->ID."\r\n";
$output .= "STATUS:".$poststatus."\r\n";
$output .= "DTSTAMP;TZID=Europe/Amsterdam:".date(DATE_ICAL, strtotime($post->post_date))."\r\n";
$output .= "DTSTART;TZID=Europe/Amsterdam:".date(DATE_ICAL, strtotime($post->post_date))."\r\n";
$output .= "DTEND;TZID=Europe/Amsterdam:".date(DATE_ICAL, strtotime($post->post_date))."\r\n";
$output .= "LAST-MODIFIED:".date(DATE_ICAL, strtotime($post->post_modified))."\r\n";
$output .= "LOCATION:STREET 01 1111 AA CITY\r\n";
$output .= "END:VEVENT\r\n";?>
<?php endforeach; ?>
<?php
// close calendar
$output .= "END:VCALENDAR";
// loop over events
echo $output;
?>
<?php }else{ ?>
    <span>No event!</span>
<?php } ?>

【问题讨论】:

    标签: android outlook calendar google-calendar-api icalendar


    【解决方案1】:

    您正在使用带有时区的日期时间格式,但与此同时,您使用 Z 表示祖鲁/UTC 时间。所以不同的客户会有不同的解读。

    只需从 DTSTART 和 DTEND 字段中删除最后的 Z。 DTSTAMP 仅以祖鲁时间表示。最后,您的 DTEND 等于您的 DTSTART,这是不合法的(必须在以后的时间,请参阅https://www.rfc-editor.org/rfc/rfc5545#section-3.8.2.2

    DTSTAMP:20170610T220000Z
    DTSTART;TZID=Europe/Amsterdam:20170610T220000
    DTEND;TZID=Europe/Amsterdam:20170610T230000
    

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,最后我用下面的方法解决了,希望对你有帮助。

      将您的日期传递给以下方法,以获取全球格林威治标准时间

      public static Date cvtToGMT(Date myDate){
          TimeZone timeZone = TimeZone.getDefault();
          Date cvtDate = new Date( myDate.getTime() - timeZone.getRawOffset());
          if(timeZone.inDaylightTime(cvtDate)){
              Date dstDate = new Date(cvtDate.getTime() - timeZone.getDSTSavings());
              if ( timeZone.inDaylightTime( dstDate )){
                  cvtDate = dstDate;
              }
          }
          return cvtDate;
      }
      

      【讨论】:

      • 您好,感谢您的回答,但需要我把它放在我的 PHP 文件的顶部,这样才能使 ical 成为 ical?可以把我的全部代码发给你吗?
      • 您使用哪种语言实现 ical?获取日期后,我们必须将其转换为 GMT 格式。
      • 用 wordpress / PHP 见上面我添加了 PHP 代码
      • 上面贴出的代码是java中的。在您的语言中,您必须将日期(以 ical 给出)转换为全局格式。
      猜你喜欢
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      相关资源
      最近更新 更多