从 Joda 的 LocalDate 获取月份和年份
Get month and year from Joda's LocalDate
我只想从 LocalDate 获取月-年字符串。
例如“2015 年 3 月”
现在我这样做如下:
myDate.monthOfYear().getAsText(LOCALE) + " " + myDate.year().getAsText(LOCALE);
有simpler/better方法吗?
是 - 只需创建一个合适的格式化程序:
DateTimeFormatter formatter = DateTimeFormat
.forPattern("MMMM yyyy")
.withLocale(LOCALE);
String text = formatter.print(myDate);
我只想从 LocalDate 获取月-年字符串。
例如“2015 年 3 月”
现在我这样做如下:
myDate.monthOfYear().getAsText(LOCALE) + " " + myDate.year().getAsText(LOCALE);
有simpler/better方法吗?
是 - 只需创建一个合适的格式化程序:
DateTimeFormatter formatter = DateTimeFormat
.forPattern("MMMM yyyy")
.withLocale(LOCALE);
String text = formatter.print(myDate);