c# – 我创建的DateTime对象和DateTime.Now之间的差异

前端之家收集整理的这篇文章主要介绍了c# – 我创建的DateTime对象和DateTime.Now之间的差异前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Exchange 2007 API查询特定用户的日历可用性.我的示例代码产生以下异常:

The time duration specified for FreeBusyViewOptions.TimeWindow is
invalid.

这是示例代码

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

service.AutodiscoverUrl("email@domain.com");

DateTime startTime = new DateTime(2012,1,6,7,0);

TimeWindow tw = new TimeWindow(startTime,startTime.AddHours(8));

GetUserAvailabilityResults result = service.GetUserAvailability(new List<AttendeeInfo> { new AttendeeInfo("email@domain.com") },tw,AvailabilityData.FreeBusyAndSuggestions);

奇怪的是,如果我用以下内容替换我的startTime赋值它可以工作:

DateTime startTime = DateTime.Now;

我创建的DateTime对象与DateTime.Now生成的对象之间有什么区别.我在调试时仔细检查了它们,但找不到区别.

有任何想法吗?

解决方法

这实际上似乎是GetUserAvailability方法中的一个问题,而不是任何DateTime操作.

根据MSDN documentation

The GetUserAvailability(Generic,TimeWindow,AvailabilityData,AvailabilityOptions) method supports only time periods that are a minimum of 24 hours long and that begin and end at 12:00a.m. To restrict the results of the method to a shorter time period,you must filter the results on the client.

猜你在找的C#相关文章