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


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


描述

這個java.time.ZoneId.getDisplayName()方法獲取區域的文本表示,例如 'British Time' 或 '+02:00'。

聲明

以下是聲明java.time.ZoneId.getDisplayName()方法。

public String getDisplayName(TextStyle style, Locale locale)

參數

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

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

返回值

區域的文本值,不為空。

示例

下麵的例子展示了 java.time.ZoneId.getDisplayName() 方法的用法。

package com.tutorialspoint;

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

public class ZoneIdDemo {
   public static void main(String[] args) {
 
      ZoneId zoneId = ZoneId.of("Z");
      System.out.println(zoneId.getDisplayName(TextStyle.SHORT,Locale.ENGLISH));  
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

Z

相關用法


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