本文介绍了Google Calendar API(Java)-创建Google Calendar Event时的时间格式无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java Google API客户端,并尝试创建Google Calendar Event.我的身份验证和日历服务初始化有效(我可以登录并获取我的日历事件).创建事件时发生问题.这是我的代码:

I'm using Java Google API client and I'm trying to create a Google Calendar Event.My authentication and calendar service initialization works (I'm able to log in and fetch my calendars events). The problem occurs when creating the event. Here is my code:

    Event event = new Event();

    event.setSummary( title );

    event.setStart( new EventDateTime().setDate( new DateTime( new Date() ) ) );
    event.setEnd( new EventDateTime().setDate( new DateTime( new Date() ) ) );

    return _calendarService.events().insert( GOOGLE_CALENDAR_ID, event ).execute();

这是我得到的错误:

有什么想法我在这里做错了吗?

Any ideas what I'm doing wrong here?

推荐答案

问题是您正在执行setDate()并传入dateTime(然后将"T15:58:06.165"附加到您的日期中) .如果需要定时事件,可以执行EventDateTime().setDateTime(),否则,可以执行以下操作:

The problem is that you are doing setDate() and passing in a dateTime (which then results in the "T15:58:06.165" appended to your date). You can either do EventDateTime().setDateTime() if you want a timed event or if not, you can do something like:

new EventDateTime().setDate(new DateTime(true, new Date(), 0));

这篇关于Google Calendar API(Java)-创建Google Calendar Event时的时间格式无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:39
查看更多