2013-02-19 60 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