有谁知道为什么我的日历对象不断打印3月份作为月份和1年份?有没有办法将日历设置为当前的月份和日期?日历对象不断打印3月份作为月份和1年份
import java.util.Date;
import java.util.GregorianCalendar;
import javafx.application.Application;
public class Calendar extends Application{
@Override
public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
// Create a calendar
GregorianCalendar calendar = new GregorianCalendar();
Date time = new Date();
calendar.setTime(time);
// Create title
Text header = new Text(getMonth(calendar.MONTH) + ", " + calendar.YEAR);
// place title in pane
pane.setTop(header);
BorderPane.setAlignment(header, Pos.CENTER);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
什么是'得到月(...)'?如果你使用'Calendar',你需要使用像'calendar.get(Calendar.MONTH)'和'calendar.get(Calendar.YEAR)''的代码。如果您使用的是Java 8,则不应该使用'Calendar',而应该使用['LocalDate'](http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html )。 –
@Rachel请在发布之前删除您的代码,以显示您的问题所需的[绝对最小值](http://stackoverflow.com/help/mcve)。 JavaFX的东西与您对日期时间的问题无关。 –