【发布时间】:2013-12-17 17:46:59
【问题描述】:
我想从我的应用程序中在 android 日历中添加一个事件。我已经使用以下代码在日历中添加了事件。
Calendar c = Calendar.getInstance();
date2 = formatter.parse(eDate);
c.setTime(date2);
c.add(Calendar.HOUR, 1);
eDate = formatter.format(c.getTime());
date2 = formatter.parse(eDate);
date2 = formatter.parse(eDate);
c.setTime(date2);
eDate = formatter.format(c.getTime());
cal1=Calendar.getInstance();
cal1.setTime(date1);
cal2=Calendar.getInstance();
cal2.setTime(date2);
calEvent.put("dtstart", cal1.getTimeInMillis());
calEvent.put("dtend", cal2.getTimeInMillis());
String timeZone = TimeZone.getDefault().getID();
calEvent.put("eventTimezone", timeZone);
Uri uri = contentResolver.insert(Uri.parse("content://com.android.calendar/events"),
calEvent);
date2 = formatter.parse(eDate);
我需要在日历上增加一小时。因此,我使用代码将结束日期增加了 1 小时:
c.add(Calendar.HOUR, 1);
但是当我查看日历时,它显示的是 12 小时活动。这意味着如果在明天晚上 10 点添加了一个事件,它会在明天晚上 10 点到明天上午 10 点创建一个事件。
谁能告诉我如何添加从明天晚上 10 点开始到明天晚上 11 点结束的活动?
【问题讨论】:
-
试试这个,calEvent.putExtra("endTime", cal.getTimeInMillis() + 60 * 1000); stackoverflow.com/questions/13268914/…
标签: java android events calendar