Hello! I add in my application "Phonebook" output logs of outgoing calls:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); cs = ctx.getContentResolver().query(CallLog.Calls.CONTENT_URI, callTableColumns, WHERE, new String[] {phoneForCallLog}, ORDER_BY); int count = 0; if (cs.moveToFirst()) { do { if (cs.getInt(cs.getColumnIndex(CallLog.Calls.TYPE)) != 3) { String number = cs.getString(cs.getColumnIndex(CallLog.Calls.NUMBER)); String duration = cs.getString(cs.getColumnIndex(CallLog.Calls.DURATION)); String date = dateFormat.format((cs.getColumnIndexOrThrow(CallLog.Calls.DATE))); 

Further, when the application starts, an incorrect date is displayed (date). Receive: 01/01/1970 03:00. The time on the emulator is set correctly. Please help with this problem.

  • And what value cs.getColumnIndexOrThrow(CallLog.Calls.DATE) method cs.getColumnIndexOrThrow(CallLog.Calls.DATE) ? - post_zeew
  • @post_zeew For example, according to the number 5 outgoing, cs.getString (cs.getColumnIndexOrThrow (CallLog.Calls.DATE)) returns: 1480057900769, 1479994378164, 1479994368616, 1479988143782, 1477569390846 - Krabs Nov. 1643916164, 1479994368616, 1479988143782, 1477569390846 - Krabs Nov. 1643616164, 1479994368616, 1479988143782, 1477569390846 - Krabs Nov. 16786978164, 1479994368616, 1479988143782

1 answer 1

If I understand correctly, you want to use the format(...) method of the SimpleDateFormat class, which takes the number of milliseconds, but now you give it a column number.

You need to get a value by the column number, and then pass this value to the foramt(...) method.

It should be something like this:

 String date = dateFormat.format(cs.getLong(cs.getColumnIndexOrThrow(CallLog.Calls.DATE))); 
  • Thank. Indeed missed this moment. Everything works with your editing without problems. - Krabs