@Test
public
void
test() {
System.out.println(String.format(
"I am %s"
,
"jj"
));
System.out.println(String.format(
"首字母是 %c"
, &#
39
;x&#
39
;));
System.out.println(String.format(
"this is %b"
,
true
));
System.out.println(String.format(
"十进制整数 %d"
,
34
));
System.out.println(String.format(
"十六进制整数 %x"
,
34
));
System.out.println(String.format(
"八进制整数 %o"
,
34
));
System.out.println(String.format(
"浮点 %f"
,
34.0
));
System.out.println(String.format(
"十六进制浮点 %a"
,
34.0
));
System.out.println(String.format(
"指数 %e"
,
34.0
));
System.out.println(String.format(
"通用浮点类型 %g"
,
34.0
));
System.out.println(String.format(
"散列码 %h"
,
34
));
System.out.println(String.format(
"百分比 %%"
));
System.out.println(String.format(
"换行 %n"
));
System.out.println(String.format(
"日期与事件类型 %ty"
,Calendar.getInstance()));
System.out.println(String.format(
"日期与事件类型 %tm"
,Calendar.getInstance()));
System.out.println(String.format(
"日期与事件类型 %te"
,Calendar.getInstance()));
System.out.println(String.format(
"%+d"
,
10
));
System.out.println(String.format(
"|%-5d|"
,
10
));
System.out.println(String.format(
"%04d"
,
10
));
System.out.println(String.format(
"%,f"
,
999999999.0
));
System.out.println(String.format(
"%(f"
, -
999999999.0
));
System.out.println(String.format(
"%#x"
,
34
));
System.out.println(String.format(
"%#o"
,
34
));
System.out.println(String.format(
"%#f"
,
34.0
));
System.out.println(String.format(
"%f 和%<3.1f"
,
34
.0f));
System.out.println(String.format(
"%3.1f"
,
34
.0f));
System.out.println(String.format(
"%2$d,%1$s"
,
"a"
,
1
));
System.out.println(String.format(
"全部日期和时间信息%tc"
,
new
Date()));
System.out.println(String.format(
"年—月—日格式%tF"
,
new
Date()));
System.out.println(String.format(
"月/日/年格式%tD"
,
new
Date()));
System.out.println(String.format(
"HH:MM:SS PM/AM格式 %tr"
,
new
Date()));
System.out.println(String.format(
"HH:MM:SS(24小时)%tT"
,
new
Date()));
System.out.println(String.format(
"HH:MM(24小时)%tR"
,
new
Date()));
System.out.println(String.format(Locale.US,
"英文月份简称%tb"
,
new
Date()));
System.out.println(String.format(
"本地月份简称%tb"
,
new
Date()));
System.out.println(String.format(Locale.US,
"英文月份全称%tB"
,
new
Date()));
System.out.println(String.format(
"本地月份全称%tB"
,
new
Date()));
System.out.println(String.format(Locale.US,
"星期简称%ta"
,
new
Date()));
System.out.println(String.format(
"星期全称%tA"
,
new
Date()));
Date date =
new
Date();
System.out.printf(
"本地星期的简称:%tA%n"
,date);
System.out.printf(
"年的前两位数字(不足两位前面补0):%tC%n"
,date);
System.out.printf(
"年的后两位数字(不足两位前面补0):%ty%n"
,date);
System.out.printf(
"一年中的天数(即年的第几天):%tj%n"
,date);
System.out.printf(
"两位数字的月份(不足两位前面补0):%tm%n"
,date);
System.out.printf(
"两位数字的日(不足两位前面补0):%td%n"
,date);
System.out.printf(
"月份的日(前面不补0):%te"
,date);
System.out.printf(
"2位数字24时制的小时(不足2位前面补0):%tH%n"
, date);
System.out.printf(
"2位数字12时制的小时(不足2位前面补0):%tI%n"
, date);
System.out.printf(
"2位数字24时制的小时(前面不补0):%tk%n"
, date);
System.out.printf(
"2位数字12时制的小时(前面不补0):%tl%n"
, date);
System.out.printf(
"2位数字的分钟(不足2位前面补0):%tM%n"
, date);
System.out.printf(
"2位数字的秒(不足2位前面补0):%tS%n"
, date);
System.out.printf(
"3位数字的毫秒(不足3位前面补0):%tL%n"
, date);
System.out.printf(
"9位数字的毫秒数(不足9位前面补0):%tN%n"
, date);
String str = String.format(Locale.US,
"小写字母的上午或下午标记(英):%tp"
, date);
System.out.println(str);
System.out.printf(
"小写字母的上午或下午标记(中):%tp%n"
, date);
System.out.printf(
"相对于GMT的RFC822时区的偏移量:%tz%n"
, date);
System.out.printf(
"时区缩写字符串:%tZ%n"
, date);
System.out.printf(
"1970-1-1 00:00:00 到现在所经过的秒数:%ts%n"
, date);
System.out.printf(
"1970-1-1 00:00:00 到现在所经过的毫秒数:%tQ%n"
, date);
}