我需要在我的 Android 应用程序中插入日历条目。现在我知道我不应该使用这种方法,但仍然如此。而且我确信我不是唯一的人...我在 stackoverflow 和互联网上进行了大量搜索,以了解我今天的代码。
事情是,事件出现了,但是日期错了,比如 1972 年。我做错了什么?
这是我的代码:
private void insertCalendar(int calChoice) {
ContentValues event = new ContentValues();
event.put("calendar_id", calChoice);
event.put("title", "WOOT");
event.put("description", "Wootification");
event.put("eventLocation", "Wootness");
event.put("allDay", 0);
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("transparency", 0);
event.put("hasAlarm", 0);
Calendar start = Calendar.getInstance();
start.set(2011, 7, 27, 8, 0, 0);
Calendar end = Calendar.getInstance();
end.set(2011, 7, 27, 9, 0, 0);
long startTime = start.getTimeInMillis();
startTime = startTime * 1000;
long endTime = end.getTimeInMillis();
endTime = endTime * 1000;
event.put("dtstart", startTime);
event.put("dtend", endTime);
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
getContentResolver().insert(eventsUri, event);
}
最佳答案
为什么要乘以 1000?
getTimeMillis 已经返回毫秒。
你似乎已经超过约会 1000 次了。
关于Android 日历 DTSTART 和 DTEND 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6847629/