Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用vCalendar忽略时区设置_Vb.net_Vcalendar - Fatal编程技术网

Vb.net 使用vCalendar忽略时区设置

Vb.net 使用vCalendar忽略时区设置,vb.net,vcalendar,Vb.net,Vcalendar,我正在尝试创建一个vCalendar约会,以发送给我们的客户。日期和时间是门诊预约的日期和时间。生成vCal的服务器在东部时间,但我们的客户端遍布全国。时间和日期与时区无关,因为它是由他们正在看的诊所设置的。我需要使用特定的日期和时间发送vCal,而不是根据时区调整的日期和时间。这是我现在使用的代码,但无论我做什么,它都会根据客户端的时区进行调整,从而导致他们的约会时间不正确 Private Function CreateCalendarItem(ByVal Mail As System.Net

我正在尝试创建一个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
任何帮助都将不胜感激。感谢您的输入。

请使用以下命令:

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时间的方式


.

根据您正在运行的版本,查看.NET中的时间是如何工作的。显然,这是前进的方向。非常感谢您的回复。我试图实现TimeZoneInfo,但结果没有改变。我仍然看到我的提醒按时区调整。Dim ApptDate As String=TimeZoneInfo.ConvertTimeToUtc(CType(ApptDateTime,DateTime)).ToString(“yyyyMMddTHHmmss”),那么如何存储ApptDateTime呢?是UTC时间还是当地时间还是其他时间?这一定是问题所在。我将约会日期作为本地时间存储在数据库中。那么在事实发生后就没有办法转换了?再次感谢您的洞察力。在设置vCalendar日期之前,您将知道约会所在的时区,并调整与东部时间的差异。看到了。非常感谢,这个特殊的代码被搁置了,所以我很久没有用它做任何事情了。我确实相信我最初是在格式中使用Z,但在vCalendar中仍然存在反映正确时间的问题。我一定会把这个拿回来,用Z重新测试,并让你们知道它是否有助于解决我的问题。