Android CalendarProvider 查询提供奇怪的开始和结束时间

Android CalendarProvider query provides strange start and end times

因此,当我向 CalendarProvider 查询我的个人日历的事件列表时,我得到了一些非常奇怪的开始和结束时间。例如,我在查询中看到的结果是 1970-01-13,但在我的 Google 日历应用程序中它正确显示为 2015-02-01。结果我得到的所有事件都有这样的奇怪时间。

我的查询如下。

 String[] mProjection = new String[]{
            Events.CALENDAR_ID,                       
            Events.ORGANIZER,
            Events.TITLE,
            Events.DTSTART,
            Events.DTEND,
            Events._ID
    };

    ContentResolver cr = getActivity().getContentResolver();
    Uri uri = Events.CONTENT_URI;
    String selection = Events.CALENDAR_ID + " = ?";
    String[] selectionArgs = new String[] {"2"};
    Cursor cur = cr.query(uri, mProjection, selection, selectionArgs, null);

    Log.i(TAG, "events " + cur.getCount());

    TextView textView = (TextView) rootView.findViewById(R.id.dummy_text);
    while (cur.moveToNext()) {
        int calID = cur.getInt(0);
        String organizer = cur.getString(1);
        String title = cur.getString(2);
        int start = cur.getInt(3);
        int end = cur.getInt(4);
        int event_id = cur.getInt(5);

        Calendar startCal = Calendar.getInstance();
        startCal.setTimeInMillis(start);
        Calendar endCal = Calendar.getInstance();
        endCal.setTimeInMillis(end);

这是我将时间转换为可读代码。

public  static String getHumanDate(int year, int month, int dayOfMonth) {
        String monthZero = "";
        String dayOfMonthZero = "";
        if ((month + 1) < 10)
            monthZero = "0";
        if (dayOfMonth < 10)
            dayOfMonthZero = "0";

        return year + "-" + monthZero + (month + 1) + "-" + dayOfMonthZero + dayOfMonth;
    }

想通了。应该用过

    long start = cur.getLong(3);
    long end = cur.getLong(4);

而不是整数