简体   繁体   English

MS Outlook 日历文件中的 UTC 时间不正确

[英]Incorrect UTC time in Calendar File for MS Outlook

In my application of event management, i create a calendar file which is sent with the registration confirmation email.在我的事件管理应用程序中,我创建了一个日历文件,该文件与注册确认电子邮件一起发送。 The application is in .NET with C#.该应用程序在 .NET 中使用 C#。 I use following code to get the time.我使用以下代码来获取时间。

sdate = row1.StartTime.ToUniversalTime().ToString("yyyyMMddThhmmssZ");
    edate = row1.EndTime.ToUniversalTime().ToString("yyyyMMddThhmmssZ");
    ...

and then i add it to calendar file然后我将它添加到日历文件中

contents.Add("DTSTART:" + sdate);
    contents.Add("DTEND:" + edate);

But the problem is that if my end time is 3:59 PM local time then it coverts correctly.但问题是,如果我的结束时间是当地时间下午 3:59,那么它会正确转换。 But if it ends at 4:00 PM then end time becomes incorrect.但如果它在下午 4:00 结束,那么结束时间就会不正确。

Can anybody guide me?有人可以指导我吗?

Please find below the Screens of Outlook Calendar Entry and Calendar File data.请在 Outlook 日历条目和日历文件数据的屏幕下方找到。

Correct Output正确的输出在此处输入图片说明

Incorrect Output错误的输出在此处输入图片说明

I finally found the solution.我终于找到了解决方案。 It is such a simple one that its disappointing that I missed it.它是如此简单,以至于我错过了它令人失望。

Just to help others.只是为了帮助别人。 I just need to put capital 'H' in the string format when converting to string.转换为字符串时,我只需要在字符串格式中输入大写的“H”。 So the correct code is所以正确的代码是

sdate = row1.StartTime.ToUniversalTime().ToString("yyyyMMddTHHmmssZ");
edate = row1.EndTime.ToUniversalTime().ToString("yyyyMMddTHHmmssZ");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM