修改了问题如何使JXDatePicker使用指定的语言?
发布于 2019-08-05 19:42:10
不幸的是,JXDatePicker依赖于旧的Java和time类,包括Date和DateFormat。这是很不幸的,因为它们的设计很糟糕,后来(5年前)被java.time (现代Java和time )所取代。您可能需要研究是否可以找到一个更现代的日期选择器组件来替换它。
否则,JXDatePicker.setFormats确实需要DateFormat对象或String对象。合理的解决方案是将一个Locale传递给您的SimpleDateFormat,然后将它传递给日期选择器:
DateFormat dateFormat = new SimpleDateFormat("E, yyyy-MM-dd", Locale.ENGLISH); 要格式化从日期选择器获得的Date,可以选择在格式化它之前将其转换为现代类型:
DateTimeFormatter dateFormatter = DateTimeFormatter
.ofPattern("E, yyyy-MM-dd", Locale.ENGLISH);
Date oldfashionedDate = DateDP.getDate();
ZonedDateTime dateTime = oldfashionedDate.toInstant().atZone(ZoneId.systemDefault());
String dateString = dateTime.format(dateFormatter);
System.out.println(dateString);指定DateTimeFormatter的英语区域设置可以确保格式化的日期在英语中为一周的一天提供缩写,例如:
星期一,2019-08-05
链接
https://stackoverflow.com/questions/57360495
复制相似问题