当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。