用Java显示每月的两位数字
使用“d”日期转换字符来显示两位数字的月份,例如27、28、20等。
System.out.printf("Two-digit day of the month: %td\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\n", d);
System.out.printf("Two-digit month: %tm\n",d);
System.out.printf("Two-digit day of the month: %td\n",d);
}
}输出结果
Current date and time = 26/11/2018 12:20:33 PM Four-digit Year = 2018 Two-digit Year = 18 Three-digit Day of the Year: 330 Two-digit month: 11 Two-digit day of the month: 26
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短