2013-02-19 57 views
1

我正在尝试为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

您需要添加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 
+0

感谢您的快速响应。但是,我怎样才能得到TZID? – Coyolero 2013-02-19 22:35:22

+1

使用TimeZoneInfor类:http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx – 2013-02-21 05:28:20

+0

我发现这[link](http://stackoverflow.com/questions/1979744/how-to- get-time-zones-in-net-framework-2-0)在framework 2.0中使用它 – Coyolero 2013-02-21 20:27:37