用 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