我正在使用iCal从门户网站生成outlook定期会议邀请。我们在门户上有不同的时区。我们将所有时间转换为IST并执行操作。我的代码如下。我面临的问题是,当一个经常性的请求是为巴黎用户生成的,一半的邀请显示正确的时间,但左循环邀请后,在日历上显示的时间之前1小时的DST (夏令时),理想情况下,它应该是相同的,而不管DST。如何处理DST,因为有多个时区具有不同的DST。您可以在我的代码中看到,我已经在IST中传递了dtParentStime和dtParentEtime父invite的开始和结束时间。
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("VERSION:2.0");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VTIMEZONE");
str.AppendLine("TZID:Asia/Kolkata");
str.AppendLine("BEGIN:STANDARD");
str.AppendLine("TZOFFSETFROM:+0530");
str.AppendLine("TZOFFSETTO:+0530");
str.AppendLine("TZNAME:IST");
str.AppendLine("END:STANDARD");
str.AppendLine("END:VTIMEZONE");
str.AppendLine("BEGIN:VEVENT");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmss}", dtParentStime)); //dtParentStime is the the parent request's start time in IST
str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmss}", dtParentEtime)); //dtParentEtime is the parent request's end time in IST
str.AppendLine(string.Format("RRULE:FREQ=WEEKLY;UNTIL={0:yyyyMMddTHHmmssZ}", utcEtime));
str.AppendLine("LOCATION: ");
str.AppendLine(string.Format("UID:{0}", meetingID));
str.AppendLine(string.Format("DESCRIPTION:{0}", msg.Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body));
str.AppendLine(string.Format("SUMMARY:{0}", msg.Subject));
str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address));
str.AppendLine("BEGIN:VALARM");
str.AppendLine("TRIGGER:-PT15M");
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
msg.AlternateViews.Add(avCal);
sc.Send(msg);我还尝试传递UTC时间作为开始和结束时间,并删除上述代码中的vtimezone部分。但问题变得更糟了。对于CET时区用户,10AM invite在上午8点出现,在dst之后出现在上午7点。
注意:-如果我使用UTC时间的开始和结束日期与vtimezone部分删除的单一邀请(非经常性邀请),那么日历时间是适当的DST之前和之后的DST以及。我是否在RRULE中遗漏了什么?
发布于 2016-10-06 00:50:57
我建议您将每个日期转换为UTC,并在格式字符串的末尾使用"Z“格式化所有日期
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", dtParentStime.ToUniversalTime()));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", dtParentEtime.ToUniversalTime()));或
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", dtParentStime.UtcDateTime));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", dtParentEtime.UtcDateTime));并删除这些行
str.AppendLine("BEGIN:VTIMEZONE");
str.AppendLine("TZID:Asia/Kolkata");
str.AppendLine("BEGIN:STANDARD");
str.AppendLine("TZOFFSETFROM:+0530");
str.AppendLine("TZOFFSETTO:+0530");
str.AppendLine("TZNAME:IST");
str.AppendLine("END:STANDARD");
str.AppendLine("END:VTIMEZONE");我希望这对你有帮助
发布于 2016-10-06 15:19:03
仅仅有VTIMEZONE定义是不够的。您需要在DTSTART和DTEND属性本身中指定TZID:
str.AppendLine(string.Format("DTSTART;TZID=Asia/Kolkata:{0:yyyyMMddTHHmmss}", dtParentStime));
str.AppendLine(string.Format("DTEND;TZID=Asia/Kolkata:{0:yyyyMMddTHHmmss}", dtParentEtime));然后,如果您希望CET用户的活动时间保持在同一时间,则需要使用CET时区,而不是亚洲/加尔各答时区。这是无计可施的。
因此,您需要将VTIMEZONE组件替换为以下内容:
BEGIN:VTIMEZONE
TZID:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
TZNAME:CET
END:STANDARD
END:VTIMEZONE并在DTSTART/DTEND中引用欧洲/巴黎TZID。当然,DTSTART/DTEND应具有与CET时间对应的值:
str.AppendLine(string.Format("DTSTART;TZID=Europe/Paris:{0:yyyyMMddTHHmmss}", dtParentStime));
str.AppendLine(string.Format("DTEND;TZID=Europe/Paris:{0:yyyyMMddTHHmmss}", dtParentEtime));https://stackoverflow.com/questions/39876821
复制相似问题