0

Calllog から通話の日付を収集していますが、日付に問題があります。simpledateformat を使用して数字をフォーマットしましたが、誤ったデータが得られました: 1903 年から 1948 年までと 1954 年から 2036 年までの年です。これは私が使用しているコードです:

 final Context context = getApplicationContext();
    final String[] projection = null;
    final String selection = android.provider.CallLog.Calls.NUMBER + "='+3620455351684'";
    final String[] selectionArgs = null;
    final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC";
    Cursor c = null;
    try{
        c = context.getContentResolver().query(
                   android.provider.CallLog.Calls.CONTENT_URI, null, selection, null, sortOrder);
        while (c.moveToNext()) { 
            String callLogID = c.getString(c.getColumnIndex(android.provider.CallLog.Calls._ID));
            int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
            int dateColumn = c.getColumnIndex(android.provider.CallLog.Calls.DATE);
            int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
            int outgoingtypeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE + "='2'");
            int durationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);
            int person = c.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME);

            int duration = c.getInt(durationColumn);
            int callDate = c.getInt(dateColumn);
            int callType = c.getInt(typeColumn);
            String number = c.getString(numberColumn);
            String personname = c.getString(person);

            SimpleDateFormat datePattern = new SimpleDateFormat ("yyyy-MM-dd");;
            datePattern.setTimeZone(TimeZone.getTimeZone("GMT"));
            String date_str = datePattern.format(new Date(callDate*1000L));

            arr_allcallsduration.add(Integer.toString(duration));
            arr_calls.add(Integer.toString(duration) + " : " + number + " : " + date_str);
        }

    }catch(Exception ex){
    }finally{
        c.close();
    }

出力:

56 : +3620455351684 : 1948-08-02

425 : +3620455351684 : 1947-06-17

337 : +3620455351684 : 1947-06-13

4

1 に答える 1

1

解決策を見つけました。callDate は次のように宣言する必要があります。

long callDate = c.getLong(dateColumn);

もう 1 つの変更:
String date_str = datePattern.format(new Date(callDate));

これが他の人に役立つことを願っています!

于 2011-10-10T20:11:24.520 に答える