我有一个名为 date
的 LocalDate
变量,当我打印它时显示 1988-05-05 我需要将其转换为 05.May 1988。如何这样做?
最佳答案
如果他从 Java 8 中的新 LocalDate 开始,SimpleDateFormat 将不起作用。据我所知,您将不得不使用 DateTimeFormatter,http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html .
LocalDate localDate = LocalDate.now();//For reference
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
String formattedString = localDate.format(formatter);
应该打印 1988 年 5 月 5 日。要获取日期之后和月份之前的时间段,您可能必须使用 "dd'.LLLL yyyy"
关于java - 如何将 LocalDate 格式化为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28177370/