有誰知道爲什麼我的日曆對象不斷打印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的東西與您對日期時間的問題無關。 –