我正在尝试创建一个vCalendar约会,以便发送给我们的客户。日期和时间是诊所预约的时间。生成vCal的服务器是在东部时间,但我们有跨越整个国家的客户端。时间和日期是独立于时区的,因为它是由他们所看的诊所设置的。我需要使用特定的日期和时间发送vCal,而不是根据时区调整的日期和时间。这是我现在使用的代码,但无论我做什么,它都会根据客户端的时区进行调整,这会导致他们约会的时间不正确。
Private Function CreateCalendarItem(ByVal Mail As System.Net.Mail.MailMessage, ByVal PlainText As String, ByVal ApptDateTime As String) As System.Net.Mail.AlternateView
Dim ApptDate As DateTime = CDate(ApptDateTime)
Dim calendarEventText As StringBuilder = New StringBuilder
calendarEventText.AppendLine("BEGIN:VCALENDAR")
calendarEventText.AppendLine("METHOD:REQUEST")
calendarEventText.AppendLine("PRODID:-//MyCompanyName")
calendarEventText.AppendLine("VERSION:2.0")
calendarEventText.AppendLine("BEGIN:VEVENT")
calendarEventText.AppendLine("DTSTART:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmss"))
calendarEventText.AppendLine("DTSTAMP:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmss"))
calendarEventText.AppendLine("DTEND:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmss"))
calendarEventText.AppendLine("UID:" & Guid.NewGuid().ToString)
calendarEventText.AppendLine("DESCRIPTION:" & PlainText)
calendarEventText.AppendLine("X-ALT-DESC;FMTTYPE=text/html:" & PlainText)
calendarEventText.AppendLine("SUMMARY:" & Mail.Subject)
calendarEventText.AppendLine("ORGANIZER:MAILTO:" & Mail.From.Address)
If Mail.To.Count > 0 Then
calendarEventText.AppendLine("ATTENDEE;CN=\" & Mail.To(0).DisplayName & "\;RSVP=FALSE:mailto:" & Mail.To(0).Address)
Else
calendarEventText.AppendLine("ATTENDEE;CN=\\;RSVP=FALSE:mailto" & "")
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 System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(calendarEventText.ToString(), ct)
Return avCal
End Function任何帮助都将不胜感激。感谢您的意见。
发布于 2015-12-11 03:27:03
使用以下内容:
calendarEventText.AppendLine("DTSTART:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmssZ"))
calendarEventText.AppendLine("DTSTAMP:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmssZ"))
calendarEventText.AppendLine("DTEND:" & ApptDate.ToUniversalTime.ToString("yyyyMMddTHHmmssZ"))请注意,我在日期-时间字符串格式的末尾添加了'Z‘。'Z‘是vCalendar文件解析器知道日期-时间值是UTC时间的方式。
https://stackoverflow.com/questions/32322143
复制相似问题