我很想知道,无论如何都要获取Google Calendar API的CalendarEntry的当前时间。
我尝试使用以下hack:
try {
if (calendarEntry.getSummary().getPlainText().equalsIgnoreCase("XXX"))
{
calendarEntry.setSummary(new PlainTextConstruct("YYY"));
}
else
{
calendarEntry.setSummary(new PlainTextConstruct("XXX"));
}
calendarEntry = calendarEntry.update();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (ServiceException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
// According to documentation, getUpdated shall returned CalendarEntry last
// update time.
// Hopefully by explicitly modify the state of calendar,
// getUpdated will return latest time.
// Unfortunately, I find out the result is not always up-to-date. It will
// return pass time still.
System.out.println("Calendar Entry = " + calendarEntry.getUpdated());
从公共时间服务器获取NTP时间是另一种选择。但是,我发现这不符合我的要求,因为浪费时间,对另一台时间服务器进行额外查询,而不是直接从Google本身检索信息。
答案 0 :(得分:0)
也许从公共时间服务器获取NTP时间是唯一的选择。