Skip to Main Content

Embedded Technologies

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

I cannot set the AM_PM Variable in my Calendar Object in ME.

2956737May 29 2015 — edited Jun 4 2015

I'm trying to determine the time and then later set the time on a Calendar object. I have tried everything I can think of and have scoured the internet but I cannot get it to work. My code is below.

I'm trying to switch the AM_PM variable in a variety of ways and I'm having trouble. No matter which way I try and set it, I cannot get it to change.

Someone on StackOverflow suggest that this may be a bug? What am I missing here?

    public void startApp() {

        Calendar cal = Calendar.getInstance();

        System.out.println(cal.get(Calendar.AM_PM)); // Original value: it is PM

        cal.add(Calendar.AM_PM, 0); // Attempt #1

        System.out.println(cal.get(Calendar.AM_PM));

      

        cal.set(Calendar.AM_PM, 0); // Attempt #2

        System.out.println(cal.get(Calendar.AM_PM));

      

        cal.set(Calendar.AM_PM, Calendar.AM); //Attempt #3

        System.out.println(cal.get(Calendar.AM_PM));

      

        cal.add(Calendar.AM_PM, Calendar.AM); //Attempt #4

        System.out.println(cal.get(Calendar.AM_PM));

      

        cal.roll(Calendar.AM, true); //Attempt #5

        System.out.println(cal.get(Calendar.AM_PM));

      

        int min = cal.get(Calendar.MINUTE);

        int sec = cal.get(Calendar.SECOND);

        int hour = cal.get(Calendar.HOUR);

        int AMPM = cal.get(Calendar.AM_PM);

        System.out.println(AMPM);

        String AMPMString = "AM";

        if(cal.get(Calendar.AM_PM)==1){

            AMPMString = "PM";

        }

        System.out.println("The time is " + hour + ":" + min + ":" + sec + " " + AMPMString);

    }

This is my output:

    1

    1

    1

    1

    1

    1

    1

    The time is 4:24:56 PM

Any ideas would be greatly appreciated!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2015
Added on May 29 2015
3 comments
1,373 views