如何将 LocalDate 格式化为用户位置的标准格式?
How to format LocalDate to the standard format for the user's location?
如何根据用户所在位置的标准格式化 LocalDate
。我想要 U.S 中的人。看到“6/28/2018”,而欧洲人看到“28/6/2018”,中国人看到“2018/6/28”。
我需要使用 DateTimeFormatter formatter = ...
还是需要使用其他东西?
我还需要根据用户位置的标准将字符串转换为 LocalDate
。
一种方法是使用 DateTimeFormatter.ofLocalizedDate()
工厂方法,其中 returns ISO 年表的区域设置特定日期格式。
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
LocalDate now = LocalDate.now(); // 2018-10-05
String txt = fmt.format(now); // Friday, 5 October 2018
LocalDate d = LocalDate.parse(txt, fmt); // 2018-10-05
如何根据用户所在位置的标准格式化 LocalDate
。我想要 U.S 中的人。看到“6/28/2018”,而欧洲人看到“28/6/2018”,中国人看到“2018/6/28”。
我需要使用 DateTimeFormatter formatter = ...
还是需要使用其他东西?
我还需要根据用户位置的标准将字符串转换为 LocalDate
。
一种方法是使用 DateTimeFormatter.ofLocalizedDate()
工厂方法,其中 returns ISO 年表的区域设置特定日期格式。
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
LocalDate now = LocalDate.now(); // 2018-10-05
String txt = fmt.format(now); // Friday, 5 October 2018
LocalDate d = LocalDate.parse(txt, fmt); // 2018-10-05