Java8微版无法设置AM_PM变量

I cannot set the AM_PM variable in Java 8 Micro Edition

我正在自学 Java 并且是初学者。作为一个更大项目的一部分,我使用 运行 代码来确定并稍后设置日历对象上的时间。我在互联网上搜索了一种设置 AM_PM 值的方法,但我无法让它工作。任何建议都会有所帮助。

package timethread;

import javax.microedition.midlet.MIDlet;
import java.util.Calendar;

/**
*
* @author Jaydawg
*/
public class TimeThread extends MIDlet {

@Override
public void startApp() {
    Calendar cal = Calendar.getInstance();
    System.out.println(cal.get(Calendar.AM_PM)); // Original value: it is '1' or 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));

    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);
}

我的结果如下:

1
1
1
1
1
1
The time is 1:20:42 PM

Java 8 Micro Edition 中的日历可能存在错误?

这对我有用 Java 7:

Calendar c = Calendar.getInstance();
c.set(Calendar.AM_PM, Calendar.AM);
System.out.println(c.get(Calendar.AM_PM));
c.set(Calendar.AM_PM, Calendar.PM);
System.out.println(c.get(Calendar.AM_PM));

它输出:

0
1

Oracle 已确认这是一个错误。

https://community.oracle.com/thread/3728182?sr=inbox&ru=997534