1.SimpleDateFormat
表示年,月,日,时,分,秒,毫秒(2016-01-15 19-48-58 362)的参数: "yyyy-MM-dd HH-mm-ss SSS"
参数表示符含义:
G 年代标志符
y <span style="font-family: Arial, Helvetica, sans-serif;">年</span>
M <span style="font-family: Arial, Helvetica, sans-serif;">月</span>
d 日
h 时(12) 在上午或下午 (1~12) 16点表示为04
H 时(24) 在一天中 (0~23) 16点表示为16
m 分
s 秒
S 毫秒
E 星期
D 一年中的第几天
F 一月中第几个星期几
w 一年中第几个星期
W 一月中第几个星期
a 上午 / 下午 标记符
k 时 在一天中 (1~24)
K 时 在上午或下午 (0~11)
z 时区
Calendar calendar = Calendar.getInstance();
calendar.set(2016, 0, 14, 15, 45, 23);//Calendar 0表示1月
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH-mm-ss SSS").format(new Date(calendar.getTimeInMillis())));
System.out.println(new SimpleDateFormat("yyyy-MM-dd hh-mm-ss SSS").format(new Date(calendar.getTimeInMillis())));
输出:
<span style="white-space:pre"> </span>2016-01-14 15-45-23 004
<span style="white-space:pre"> </span>2016-01-14 03-45-23 004