Java日期處理
格式化輸出Date
public class Test {
public static void main(String[] args) {
// Calendar calendar=Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"E--yyyy年M月dd日HH時mm分ss秒", Locale.SIMPLIFIED_CHINESE);
// sdf.applyPattern("yyyy年MM月dd日HH時mm分ss秒");
String timeStr = simpleDateFormat.format(Calendar.getInstance()
.getTime());
String timeStr2 = simpleDateFormat.format(new Date().getTime());
System.out.println(timeStr);
}
}
日期和時間格式由<EM>日期和時間模式</EM> 字符串指定。public static void main(String[] args) {
// Calendar calendar=Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"E--yyyy年M月dd日HH時mm分ss秒", Locale.SIMPLIFIED_CHINESE);
// sdf.applyPattern("yyyy年MM月dd日HH時mm分ss秒");
String timeStr = simpleDateFormat.format(Calendar.getInstance()
.getTime());
String timeStr2 = simpleDateFormat.format(new Date().getTime());
System.out.println(timeStr);
}
}
字母 | 日期或時間元素 | 表示 | 示例 |
---|---|---|---|
G |
Era 標志符 | Text | AD |
y |
年 | Year | 1996 ; 96 |
M |
年中的月份 | Month | July |
w |
年中的周數 | Number | 27 |
W |
月份中的周數 | Number | 2 |
D |
年中的天數 | Number | 189 |
d |
月份中的天數 | Number | 10 |
F |
月份中的星期 | Number | 2 |
E |
星期中的天數 | Text | Tuesday |
a |
Am/pm 標記 | Text | PM |
H |
一天中小時數0-23 | Number | 0 |
k |
一天中小時數1-24 | Number | 24 |
K |
am/pm中小時數0-11 | Number | 0 |
h |
am/pm中小時數1-12 | Number | 12 |
m |
小時中的分鐘數 | Number | 30 |
s |
分鐘中的秒數 | Number | 55 |
S |
毫秒數 | Number | 978 |
z |
時區 | General time zone | GMT-08:00 |
Z |
時區 | RFC 822 time zone | -0800 |
posted on 2007-09-12 21:31 月芽兒 閱讀(245) 評論(0) 編輯 收藏 所屬分類: J2EE學習心得