2017-04-12 101 views

回答

4

您正在寻找的字符串是MMMM

来源:DateTimeFormatter Javadoc

+0

谢谢。整天怎么样? –

+0

整天在...... –

+0

哦,整天是EEEE!从你的javadoc得到它。谢谢。 –

1

TL;博士

使用自动定位。无需指定格式化模式。

localDate.format( 
    DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) 
        .withLocale(Locale.UK) 
) 

周一,2017年1月23日

以你的标题夸张地说,我会使用得心应手Month枚举。

LocalDate ld = LocalDate.of(2017 , Month.JANUARY , 23); 
Month month = ld.getMonth() ; // Returns a `Month` object, whereas `getMonthValue` returns an integer month number (1-12). 

让java.time做自动本地化的工作。要进行本地化,请指定:

  • TextStyle确定字符串的长度或缩写长度。
  • Locale确定(a)用于翻译日期名称,月份名称等的人类语言,以及(b)用于确定缩写,大写,标点符号,分隔符等问题的文化规范。

例如:

String output = month.getDisplayName(TextStyle.FULL , Locale.CANADA_FRENCH) ; // Or Locale.US, Locale.KOREA, etc. 

维耶

日期

如果你想整个日期本地化,让DateTimeFormatter做的工作。这里我们使用FormatStyle而不是TextStyle

实施例:

Locale l = Locale.CANADA_FRENCH ; // Or Locale.US, Locale.KOREA, etc. 
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) 
             .withLocale(l) ; 
String output = ld.format(f); 

dimanche 23维耶2107

2

是。现在可以完成。

LocalDate dd = new LocalDate(); //pass in a date value or params(yyyy,mm) 

String ss = dd.monthOfYear.getAsText(); // will give the full name of the month 
String sh = dd.monthOfYear.getAsShortText(); // shortform