Cannot get Correct month for a call from call log history
I am trying to extract information from the call log of the android. I am getting the call date that is one month back from the actual time of call. I mean to say that the information extracted by my code for the date of call is one mont back than the actual call date.
I have the following in the Emulator:
I saved a contact. Then I made a call to the contact.
Code:
I have 3 ways of extracting call Date information but getting the same wrong result. My code is as follows:
/* Make the query to call log content */
Cursor callLogResult = context.getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, null, null, null);
int columnIndex = callLogResult.getColumnIndex(Calls.DATE);
Long timeInResult = callLogResult.getLong(columnIndex);
/* Meth开发者_如何学JAVAod 1 to change the milliseconds obtained to the readable date formate */
Time time = new Time();
time.toMillis(true);
time.set(timeInResult);
String callDate= time.monthDay+"-"+time.month+"-"+time.year;
/* Method 2 for extracting the date from tha value read from the column */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
String Month = calendar.get(Calendar.MONTH) ;
/* Method 3 for extracting date from the result obtained */
Date date = new Date(timeInResult);
String mont = date.getMonth()
While using the Calendar method , I also tried to set the DayLight SAving Offset but it didnot worked,
calendar.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
int DST_OFFSET = calendar.get( Calendar.DST_OFFSET ); // DST_OFFSET
Boolean isSet = calendar.getTimeZone().useDaylightTime();
if(isSet)
calendar.set(Calendar.DST_OFFSET , 0);
int reCheck = calendar.get(Calendar.DST_OFFSET );
But the value is not set to 0 in recheck. I am getting the wrong month value by using this also.
Please some one help me where I am wrong? or is this the error in emulator ??
Thanks, Nishant Kumar Engineering Student
Calandar's months are from 0 to 11 You need to add 1 to the month Caladar is giving you. I know, this is strange.
Try new Date(timeInResult);
精彩评论