java.time.Month.getDisplayName() 方法示例



描述

java.time.Month.getDisplayName(TextStyle style, Locale locale) 方法獲取文字表示形式,例如“1 月”或“12 月”。

宣告

以下是 java.time.Month.getDisplayName(TextStyle style, Locale locale) 方法的宣告。

public String getDisplayName(TextStyle style, Locale locale)

引數

  • style − 所需的文字長度,非空。

  • locale − 要使用的語言環境,非空。

返回值

年月文字值,非空。

示例

以下示例展示了 java.time.Month.getDisplayName(TextStyle style, Locale locale) 方法的用法。

package com.tutorialspoint;

import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;

public class MonthDemo {
   public static void main(String[] args) {
 
      Month day = Month.of(3);
      System.out.println(day.getDisplayName(TextStyle.SHORT,Locale.ENGLISH));  
   }
}

讓我們編譯並執行上述程式,它將產生以下結果 −

Mar
廣告
© . All rights reserved.