1.使用SimpleDateFormat格式化日期.
SimpleDateFormat是一个以语言环境敏感的方式来格式化和分析日期的类。SimpleDateFormat允许 你选择任何用户自定义日期时间格式来运行。
例如:
public static void main(String args[]) {
Date dNow = new Date( );
SimpleDateFormat ft =new SimpleDateFormat (“E yyyy.MM.dd ‘at’ hh:mm:ss a zzz”);
System.out.println("Current Date: " + ft.format(dNow));
}
//结果如下:Current Date: Sun 2004.07.18 at 04:14:09 PM PDT
2.简单的DateFormat格式化编码.
时间模式字符串用来指定时间格式。在此模式中,所有的ASCII字母被保留为模式字母,定义如下:
字母 描述 示例
G 纪元标记 AD
y 四位年份 2001
M 月份 July or 07
d 一个月的日期 10
h A.M./P.M. (1~12)格式小时 12
H 一天中的小时 (0~23) 22
m 分钟数 30
s 秒数 55
S 微妙数 234
E 星期几 Tuesday
D 一年中的日子 360
F 一个月中第几周的周几 2 (second Wed. in July)
w 一年中第几周 40
W 一个月中第几周 1
a A.M./P.M. 标记 PM
k 一天中的小时(1~24) 24
K A.M./P.M. (0~11)格式小时 10
z 时区 Eastern Standard Time
’ 文字定界符 Delimiter
" 单引号 `