public static void see(String str){
System.out.println(str);
}
public void test(){
//默认环境日期格式
SimpleDateFormat sdf=new SimpleDateFormat();
String pattern=sdf.toPattern();
String date=sdf.format(new Date());
see(pattern);
see(date);
//yyyy-MM-dd HH:mm:ss(2009-11-02 09:32:15)
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String pattern1=sdf1.toPattern();
String date1=sdf1.format(new Date());
see(pattern1);
see(date1);
//yyyy年MM月dd日 a h:mm:ss(2009年11月02日 上午 09:32:15)
SimpleDateFormat sdf2=new SimpleDateFormat("yyyy年MM月dd日 a h:mm:ss");
String pattern2=sdf2.toPattern();
String date2=sdf2.format(new Date());
see(pattern2);
see(date2);
}
附模式匹配目录:
| 字母
| 日期或时间元素
| 表示
| 示例
|
G
| Era 标志符
|
| AD
|
y
| 年
|
| 1996; 96
|
M
| 年中的月份
|
| July; Jul; 07
|
w
| 年中的周数
|
| 27
|
W
| 月份中的周数
|
| 2
|
D
| 年中的天数
|
| 189
|
d
| 月份中的天数
|
| 10
|
F
| 月份中的星期
|
| 2
|
E
| 星期中的天数
|
| Tuesday; Tue
|
a
| Am/pm 标记
|
| PM
|
H
| 一天中的小时数(0-23)
|
| 0
|
k
| 一天中的小时数(1-24)
|
| 24
|
K
| am/pm 中的小时数(0-11)
|
| 0
|
h
| am/pm 中的小时数(1-12)
|
| 12
|
m
| 小时中的分钟数
|
| 30
|
s
| 分钟中的秒数
|
| 55
|
S
| 毫秒数
|
| 978
|
z
| 时区
|
| Pacific Standard Time; PST; GMT-08:00
|
Z
| 时区
|
|
-0800
|
阅读(1251) | 评论(0) | 转发(0) |