首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vCalendar忽略时区设置

使用vCalendar忽略时区设置
EN

Stack Overflow用户
提问于 2015-09-01 09:15:11
回答 1查看 550关注 0票数 0

我正在尝试创建一个vCalendar约会,以便发送给我们的客户。日期和时间是诊所预约的时间。生成vCal的服务器是在东部时间,但我们有跨越整个国家的客户端。时间和日期是独立于时区的,因为它是由他们所看的诊所设置的。我需要使用特定的日期和时间发送vCal,而不是根据时区调整的日期和时间。这是我现在使用的代码,但无论我做什么,它都会根据客户端的时区进行调整,这会导致他们约会的时间不正确。

代码语言:javascript
复制
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

任何帮助都将不胜感激。感谢您的意见。

EN

回答 1

Stack Overflow用户

发布于 2015-12-11 03:27:03

使用以下内容:

代码语言:javascript
复制
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时间的方式。

See the RFC 5545 Date-Time spec info

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32322143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档