Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

calender class problem

Hi,

         i set day,month,year,hour of the day and minute in calender class..but when i get the time in milliseconds from the calender object it  give small variation in time from the previous one.please suggest why.....

Developer
Posts: 16,676
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: calender class problem

what do you mean with "previous one"?
maybe you should set the millisecond field to 0 (if i understand the problem at all).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: calender class problem

Hi ,

             How i can do this?....

Developer
Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: calender class problem

I am guessing that the prolbem is you are using Calendar.getInstrance() to get a Celendar Object, and as a result, getting a Calendar set to the current time.  if you reset the date hour and minute, then that will leave the seconds and millseconds as they were at the instant you did the getInstance().

 

The easiest way to clear these values is to use

DateTimeUtilities.zeroCalendarTime(<your calendar Object>);

Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: calender class problem

Hi ,

         i use the below code..same value set in calender class but it gives different value every time....


public class TimeConverter extends MainScreen implements FieldChangeListener
{
ButtonField b;
TimeConverter()
{
b=new ButtonField("Run",ButtonField.CONSUME_CLICK);
add(b);
b.setChangeListener(this);
}
public void fieldChanged(Field field, int context)
{
Calendar cl=Calendar.getInstance();
cl.set(Calendar.DAY_OF_MONTH,8);
cl.set(Calendar.MONTH,Calendar.AUGUST);
cl.set(Calendar.YEAR,2012);
cl.set(Calendar.HOUR_OF_DAY,8);
cl.set(Calendar.MINUTE,30);


System.out.println("...........Calender ->"+cl.getTime().getTime());

}
}

 

pls suggest.........

 

Developer
Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: calender class problem

The reason this is happening and the solution is given in my previous post. 

Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: calender class problem

Hi,

        it set the last  fields to 0 (as the result exact value change)..but i  want the exact value...

Developer
Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: calender class problem

Sorry I do not understand.

 

Just to confirm, you clear the time values to 0 before setting the hour and minute times.

 

If you have code that includes this and still shows a variation, please post that code and explain what variatons you see and how you see them.

Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: calender class problem

Hi,

           i use the below code..

 

public class TimeConverter extends MainScreen implements FieldChangeListener
{
ButtonField b;
DateField df;
TimeConverter()
{
b=new ButtonField("Run",ButtonField.CONSUME_CLICK);
add(b);
b.setChangeListener(this);

SimpleDateFormat dateFormat=new SimpleDateFormat("dd/MM/yyyy hh:mm");
df=new DateField("SetTime",System.currentTimeMillis(),dateFormat);
add(df);
}
public void fieldChanged(Field field, int context)
{

Calendar cl=Calendar.getInstance();
DateTimeUtilities.zeroCalendarTime(cl);
cl.set(Calendar.DAY_OF_MONTH,8);
cl.set(Calendar.MONTH,Calendar.AUGUST);
cl.set(Calendar.YEAR,2012);
cl.set(Calendar.HOUR_OF_DAY,8);
cl.set(Calendar.MINUTE,30);

System.out.println("Date Field Time ...."+df.getDate());

System.out.println("...........Calender ->"+cl.getTime().getTime());

}
}

 

wt i am doing..

   1)    i use the calender class object and the  value of its object  set at that time...

   2)   then there is a date field on which i set the current time..

         before the button click i set the value datefield ( in  ui ) as same as the calender object..

         and i get slightly difference in output...pls suggest why..

 

 

Date Field Time ....1347785979985
...........Calender ->1344414600000

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: calender class problem

You set the calendar object to august but the current date is september, which if you check the results is what the time represent.