如何使用时区支持创建日历约会

时间:2013-02-19 22:12:01

标签: .net vb.net email outlook html-email

我正在尝试为outlook创建一个新的日历活动。它创建成功但是当来自另一个国家(另一个区域时间)的某个人打开它时,日期和时间不正确。

这是代码

Dim calendarEventText As StringBuilder = New StringBuilder
calendarEventText.AppendLine("BEGIN:VCALENDAR")
calendarEventText.AppendLine("PRODID:-//Company Name")
calendarEventText.AppendLine("VERSION:2.0")
calendarEventText.AppendLine("METHOD:REQUEST")
calendarEventText.AppendLine("BEGIN:VEVENT")
calendarEventText.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", Convert.ToDateTime(changeStartDate.ToString)))
' I'm using the UTC time
calendarEventText.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow))
calendarEventText.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", Convert.ToDateTime(changeEndDate.ToString)))
calendarEventText.AppendLine(String.Format("LOCATION:{0}", location.ToString))
calendarEventText.AppendLine(String.Format("UID:{0}", Guid.NewGuid()))
calendarEventText.AppendLine(String.Format("DESCRIPTION:{0}", _mail.Body))
calendarEventText.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", _mail.Body))
calendarEventText.AppendLine(String.Format("SUMMARY:{0}", _mail.Subject))
calendarEventText.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", _mail.From.Address))
If _mail.To.Count > 0 Then
    calendarEventText.AppendLine(String.Format("ATTENDEE;CN=\{0}\;RSVP=TRUE:mailto:{1}", _mail.To(0).DisplayName, _mail.To(0).Address))
Else
    calendarEventText.AppendLine(String.Format("ATTENDEE;CN=\{0}\;RSVP=TRUE:mailto:{1}", "", ""))
End If
calendarEventText.AppendLine("BEGIN:VALARM")
calendarEventText.AppendLine("TRIGGER:-PT15M")
calendarEventText.AppendLine("ACTION:DISPLAY")
calendarEventText.AppendLine("DESCRIPTION:Reminder")
calendarEventText.AppendLine("END:VALARM")
calendarEventText.AppendLine("END:VEVENT")
calendarEventText.AppendLine("END:VCALENDAR")
Dim ct As System.Net.Mime.ContentType = New System.Net.Mime.ContentType("text/calendar")
ct.Parameters.Add("method", "REQUEST")
Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(calendarEventText.ToString(), ct)

如何添加时区支持?

环境:

  • .NET 2.0

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您需要添加VTIMEZONE部分(见下文)并在指定时间时使用该时区,例如

DTSTART;TZID="USA Mountain Standard Time!":20110627T080000


BEGIN:VTIMEZONE
TZID:USA Mountain Standard Time!
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:-0600
TZOFFSETTO:-0700
END:STANDARD
END:VTIMEZONE