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



說明

java.time.ZoneId.getDisplayName() 方法獲取區域的文字表示形式,例如“英國時間”或“+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
廣告
© . All rights reserved.