2017-04-12 54 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