在 Java 中運用 printf 方法顯示本地化的月份名稱


若要在 Java 中顯示本地化的月份名稱,請使用轉換字元“B”。

System.out.printf("Localized month : %TB", d);

若要以小寫顯示方法名稱,請使用“%tb”。

System.out.printf("
Localized month : %tB
", d);

示例

 線上演示

import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      Date d = new Date();
      System.out.printf("Morning/afternoon indicator: %tp",d);
      System.out.printf("
Morning/afternoon indicator: %Tp",d);       System.out.printf("
Localized month : %tB
", d);       System.out.printf("Localized month : %TB", d);    } }

輸出

Morning/afternoon indicator: pm
Morning/afternoon indicator: PM
Localized month : November
Localized month : NOVEMBER

在 Java 中右對齊和左對齊值

更新於:27-Jun-2020

102 次瀏覽

開啟你的職業生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.