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: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone
Accepted Solution

Returns the Value of hour in calendar Zero

Hi I write a below code with Calendar that return the value zero For HOUR_OF_DAY and MINUTE When I Run this code in Strom2(9550-5.0.0.334).

 

Calendar calendar = Calendar.getInstance();
Date date = new Date(this.arrivalTimeField.getDate());
calendar.setTime(date);
int day = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);

 

So please help me for this issue and Thanks in Advanced

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

Re: Returns the Value of hour in calendar Zero

Code looks fine, are you sure that the hour is not actually 0?

 

Try printing the date you get using SimpleDateFormat to see the value you are really getting.

 

Alternatively, change HOUR_OF_DAY to HOUR, and then you will see 12. 

 

 

Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Returns the Value of hour in calendar Zero

Look  at this full code when i press the OK Buttton and Cancel Button it gives me the Different Value for the Data and give the day and Minute Vilue  Zero when i press  Cancel

 

 

if (field.equals(this.arrivalDateField)
                || field.equals(this.arrivalTimeField)
                || field.equals(this.departureTimeField)
                || field.equals(this.departureTimeField)) {

            VirtualKeyboard keyboard = SearchScreen.this.getVirtualKeyboard();
            keyboard.setVisibility(VirtualKeyboard.HIDE);

            
            Calendar calendar = Calendar.getInstance();
            Date date = new Date(this.arrivalTimeField.getDate());
            calendar.setTime(date);
            int day = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);
            long time = (day * 60 * 60 * 1000) + (minute * 60 * 1000);
            Date arrivalDate = new Date(this.arrivalDateField.getDate() + time);
            if (arrivalDate.getTime() > 0
                    && arrivalDate.getTime() < this.arrivaCalendar.getTime()
                            .getTime()) {
                Dialog.alert(ConstantData.previousTime);
                this.arrivalDateField
                        .setDate(this.arrivaDateCalendar.getTime());
                this.arrivalTimeField
                        .setDate(this.arrivaTimeCalendar.getTime());
                return;
            }
        }

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

Re: Returns the Value of hour in calendar Zero

I have had many problems like this myself.  Invariably I find that the bug is my code.  Usually it is not difficult to find by using the appropriate debugging or SimpleDateFormat (because times are difficult to interpret,, it is good to let the system do it for you!).  I suggest you do the same here. 

 

If you find that the system is not doing what you expect, then give us the details, for example, give us the long value that you supply to the Calendar, and the hour that you get out. You should be able to do this in two or three lines, just using standard RIM Java (i.e. none of your classes).  You might also want to tell us the TimeZone you are testing in. 

Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Returns the Value of hour in calendar Zero

Hi peter, as you describe I check my code but not find any issue so I send you my code and its value below so please check it an tell me is I making mistake  and doing some wrong with dataFied or calendar.

 

 

Declaration:-

 

 

arrivalTimeField = new DateField("", arrivaTimeCalendar.getTime()
                                .getTime(), timeFormat, DateField.TIME) {

                        protected void paint(Graphics graphics) {
                                graphics.setColor(Color.WHITE);
                                super.paint(graphics);
                        }

                };
                // arrivalTimeField.setMinuteIncrements(5 * 60 * 1000);
                arrivalTimeField.setFont(getFont().derive(Font.BOLD, 17));
                if (DeviceInfo.getDeviceName().endsWith("9500")
                                || DeviceInfo.getDeviceName().endsWith("9530")) {
                        arrivalTimeField.setMargin(5, 9, 0, 0);
                } else {
                        arrivalTimeField.setMargin(2, 9, 0, 0);
                }

                arrivalTimeField.setChangeListener(this);
                arrivalTimeField.setFocusListener(this);
                arrivalTimeManager.add(arrivalTimeField);

 

 

LIstner Code:-

 

if (field.equals(this.arrivalDateField)
                                || field.equals(this.arrivalTimeField)
                                || field.equals(this.departureTimeField)
                                || field.equals(this.departureTimeField)) {

                        VirtualKeyboard keyboard = SearchScreen.this.getVirtualKeyboard();
                        keyboard.setVisibility(VirtualKeyboard.HIDE);

                        SimpleDateFormat formatTopass = new SimpleDateFormat(
                                        "yyyy-MM-dd HH:mm");
                        Calendar calendar = Calendar.getInstance();
                        long dateVlaue = this.arrivalTimeField.getDate();
                        Date date = new Date(dateVlaue);
                        String string = formatTopass.format(date);
                        calendar.setTime(date);
                        int day = calendar.get(Calendar.HOUR_OF_DAY);
                        int minute = calendar.get(Calendar.MINUTE);
                        long time = (day * 60 * 60 * 1000) + (minute * 60 * 1000);
                        Date arrivalDate = new Date(this.arrivalDateField.getDate() + time);
                        if (arrivalDate.getTime() > 0
                                        && arrivalDate.getTime() < this.arrivaCalendar.getTime()
                                                        .getTime()) {
                                Dialog.alert(ConstantData.previousTime);
                                this.arrivalDateField
                                                .setDate(this.arrivaDateCalendar.getTime());
                                this.arrivalTimeField
                                                .setDate(this.arrivaTimeCalendar.getTime());
                                return;
                        }
                }

 

 

When i chenge the time to 09:08 Am the value of dateVlaue=(-6267445505562L) and when i click the date field and press calcle for the value in date Field is same but it gieves me string value(00:00) and the date value for that id value=(-621674478399822L). so please check this and reply me if you find any thing wrong in it.

Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Returns the Value of hour in calendar Zero

Hi peter,

may be the mistake in my code because it fires the field change event when I click the cancel button, it not firer in the test application I create so please check it.

Developer
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Returns the Value of hour in calendar Zero

HI

My problem is solved because I set the the when I set the date in dateField I set the time using the calendar instance so when I set year ,month and date to  0 it fires the Field changeEvent and so get the 0 value in strom2 but in storm is working properly so thanks peter.