【发布时间】:2016-09-27 11:00:02
【问题描述】:
我正在使用自定义日期选择器(由 JFeonix 制造,它允许您选择时间,与 google 日历等 Android 应用程序中看到的相同)。
类似于使用带有 DateTimeFormatter 的 LocaleDate 为日期选择器设置值的方式,我正在尝试为这个时间选择器实现相同的功能,只是我的代码似乎不起作用。
这是我用来设置 datePickers 值的:
String dateWord = "2016-08-17";
createConsultationController.datePicker.setValue(localDate(dateWord));
public static final LocalDate localDate (String dateString){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(dateString, formatter);
return localDate;
}
这就是我试图设置“时间日期选择器”的方法,但没有运气:
String startTime = "11:00";
createConsultationController.startTime.setValue(localeTime(startTime));
public static final LocalDate localeTime (String timeString) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm");
LocalDate localTime = LocalDate.parse(timeString, formatter);
return localTime;
}
堆栈跟踪的第一行说:
Exception in thread "JavaFX Application Thread" java.time.format.DateTimeParseException: Text '11:00' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MinuteOfHour=0, HourOfAmPm=11},ISO of type java.time.format.Parsed
【问题讨论】:
-
您是否故意使用 12 小时“hh”而不是 24 小时“HH”?
-
不,不确定区别。我把它改成 HH 并没有改变任何东西
标签: android javafx datepicker javafx-2