Cannot get Correct month for a call from call log history
<p>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.</p>

<p>I have the following in the Emulator:</p>

<p>I saved a contact. Then I made a call to the contact.</p>

<p>Code: </p>

<p>I have 3 ways of extracting call Date information but getting the same
wrong result.  My code is as follows:</p>

<p>/*  Make the query to call log content */</p>

<p>Cursor callLogResult =
context.getContentResolver().query( CallLog.Calls.CONTENT_URI,
                                                                                            null, null,  null, null);</p>

<pre><code>int    columnIndex =  callLogResult.getColumnIndex(Calls.DATE);

Long timeInResult = callLogResult.getLong(columnIndex);
</code></pre>

<p>/* Method 1 to change the milliseconds obtained to the readable date
formate */</p>

<pre><code>            Time time = new Time();
            time.toMillis(true);
            time.set(timeInResult);
</code></pre>

<p>String callDate= time.monthDay+"-"+time.month+"-"+time.year;</p>

<p>/*  Method 2 for extracting the date from tha value read from the
column */</p>

<pre><code>           Calendar calendar =  Calendar.getInstance();
           calendar.setTimeInMillis(time);
           String  Month = calendar.get(Calendar.MONTH) ;
</code></pre>

<p>/* Method 3 for extracting date from the result obtained  */</p>

<pre><code>          Date date = new Date(timeInResult);
          String mont = date.getMonth()
</code></pre>

<p>While using the Calendar method , I also tried to set the DayLight
SAving Offset but it didnot worked,</p>

<pre><code>      calendar.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
      int DST_OFFSET = calendar.get(  Calendar.DST_OFFSET );   //
</code></pre>

<p>DST_OFFSET</p>

<pre><code>      Boolean isSet = calendar.getTimeZone().useDaylightTime();

      if(isSet)
      calendar.set(Calendar.DST_OFFSET , 0);

      int reCheck = calendar.get(Calendar.DST_OFFSET );
</code></pre>

<p>But the value is not set to 0 in recheck.  I am getting the wrong
month value by using this also.</p>

<p>Please some one  help me where I am wrong?  or is this the error in
emulator ??</p>

<p>Thanks,
Nishant Kumar
Engineering Student</p>
