我有一个可以实时显示时间计数的代码,但是问题是显示格式本身不合适。当前显示类似1:1:1
的内容,需要显示类似01:01:01
这是我的代码:
ZonedDateTime currentTime = ZonedDateTime.now(ZoneId.of("Europe/Berlin"));
Timeline clock = new Timeline(new KeyFrame(Duration.ZERO, e -> {
String currentDay = String.format("%tA", currentTime);
String second = String.valueOf(currentTime.now().getSecond());
String minute = String.valueOf(currentTime.now().getMinute());
String hour = String.valueOf(currentTime.now().getHour());
String CEST = String.format("%tZ", currentTime);
String day = String.format("%td", currentTime);
String month = String.format("%tB", currentTime);
int Year = currentTime.now().getYear();
currentDateTime.setText(currentDay + ", " + hour + ":" + (minute) + ":" + second + ", " + CEST + " " + day + " " + month + " " + Year);
}),
new KeyFrame(Duration.seconds(1))
);
clock.setCycleCount(Animation.INDEFINITE);
clock.play();
告诉我如何格式化输出?