用 Java 按名稱和數字顯示月份
使用“b”轉換字元來顯示 Java 中的月份名稱。
使用“m”轉換字元來顯示 Java 中的月份數字。
在這裡,我們使用格式化程式和日曆類,因此匯入以下包。
import java.util.Calendar; import java.util.Formatter;
下面是顯示月份名稱和數字的一個示例 −
示例
import java.util.Calendar;
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f = new Formatter();
Calendar cal = Calendar.getInstance();
System.out.println("Current date and time: "+cal.getTime());
f = new Formatter();
System.out.println(f.format("Month = %tb
Month Number = %tm", cal, cal));
}
}輸出
Current date and time: Mon Nov 26 07:07:31 UTC 2018 Month = Nov Month Number = 11
廣告
資料結構
網路連線
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP