【发布时间】:2018-03-16 00:18:44
【问题描述】:
我正在尝试从 vb.net 中的 winforms 应用程序在 google 日历中创建一个全天活动。我可以使用开始和结束时间很好地创建一个事件,但我不知道如何整天制作一个事件。下面注释掉的代码适用于“一天中的时间”事件。
'Dim CalendarEvent As New Data.Event
'Dim StartDateTime As New Data.EventDateTime
'Dim datestr As String
'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 07:00 am"
'StartDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
'datestr = UIFORM.REQDATE.Value.ToString("dd/MM/yyyy") & " 03:00 pm"
'Dim EndDateTime As New Data.EventDateTime
'EndDateTime.DateTime = Date.ParseExact(datestr, "dd/MM/yyyy hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
'CalendarEvent.Start = StartDateTime
'CalendarEvent.End = EndDateTime
'CalendarEvent.Description = "Inserted from Order Entry"
'CalendarEvent.Summary = NUMBER & " - " & NAME
'Authenticate()
'service.Events.Insert(CalendarEvent, "primary").Execute()
根据一些消息来源,我只需要指定日期而不需要全天进行活动的时间。这是我尝试过的:
Dim CalendarEvent As New Data.Event
Dim datestr As String
datestr = UIFORM.REQDATE.Value.ToString("yyyy-MM-dd")
CalendarEvent.Start.Date = datestr
CalendarEvent.End.Date = datestr
CalendarEvent.Description = "Inserted from Order Entry"
CalendarEvent.Summary = "all day test"
Authenticate()
service.Events.Insert(CalendarEvent, "primary").Execute()
一旦遇到 CalendarEvent.Start.Date = datestr,我就会收到对象引用错误。
【问题讨论】:
-
看起来
CalendarEvent.Start指的是DateTime属性。DateTime值的Date属性是 ReadOnly。此外,DateTime值总是具有时间分量。即使您为其分配了仅日期值,该属性仍将具有午夜的时间分量。要发送一个完全没有时间组件的值,您可能需要进入较低级别并构建自定义 JSON 请求。 -
我理解了大约一半。你说的低级是什么意思?应该只有一个布尔值 .allday=true... 但不,Google 必须复杂
-
没关系...我终于找到了日历 API 的正确文档,它根本不是
DateTime属性。 API 有自己的EventDateTime类型:developers.google.com/resources/api-libraries/documentation/…
标签: vb.net google-calendar-api