用Java显示两位数的月份
使用“m”日期转换字符来显示两位数的月份。
System.out.printf("Two-digit month: %tm\n",d);上面的d是一个日期对象-
Date d = new Date();
以下是一个例子-
示例
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Demo {
public static void main(String[] args) throws Exception {
Date d = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
String format = dateFormat.format(d);
System.out.println("Current date and time = " + format);
System.out.printf("Four-digit Year = %TY\n",d);
System.out.printf("Two-digit Year = %ty\n",d);
System.out.printf("Three-digit Day of the Year: %tj/%Tj\n", d, d);
System.out.printf("Two-digit month: %tm\n",d);
}
}输出结果
Current date and time = 26/11/2018 12:18:51 PM Four-digit Year = 2018 Two-digit Year = 18 Three-digit Day of the Year: 330/330 Two-digit month: 11
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短