當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java java.time.Month.getDisplayName()用法及代碼示例


描述

這個java.time.Month.getDisplayName(TextStyle style, Locale locale)方法獲取文本表示,例如 'Jan' 或 'December'。

聲明

以下是聲明java.time.Month.getDisplayName(TextStyle style, Locale locale)方法。

public String getDisplayName(TextStyle style, Locale locale)

參數

  • style- 所需文本的長度,不為空。

  • locale- 要使用的語言環境,不為空。

返回值

month-of-year 的文本值,不為空。

示例

下麵的例子展示了 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

相關用法


注:本文由純淨天空篩選整理自 java.time.Month.getDisplayName() Method Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。