在Java中按名称和数字显示月份
在Java中,将“b”转换字符用作月份名称。
在Java中,将'm'转换字符用作月份号。
在这里,我们使用Formatter和Calendar类,因此导入以下包。
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 \nMonth Number = %tm", cal, cal));
}
}输出结果
Current date and time: Mon Nov 26 07:07:31 UTC 2018 Month = Nov Month Number = 11
热门推荐
10 六十岁大寿祝福语简短
11 端午老师祝福语简短优美
12 聚餐会祝福语简短
13 发廊元旦祝福语大全简短
14 满月100天简短祝福语
15 怎么生孩子祝福语简短
16 团队文案祝福语简短励志
17 药店祝福语简短10字
18 杨奕老师祝福语简短