public class SimpleDateFormat extends DateFormat
SimpleDateFormat 是一個(gè)以國(guó)別敏感的方式格式化和分析數(shù)據(jù)的具體類。 它允許格式化 (date -> text)、語法分析 (text -> date)和標(biāo)準(zhǔn)化。
SimpleDateFormat 允許以為日期-時(shí)間格式化選擇任何用戶指定的方式啟動(dòng)。 但是,希望用 DateFormat 中的 getTimeInstance、 getDateInstance 或 getDateTimeInstance 創(chuàng)建一個(gè)日期-時(shí)間格式化程序。 每個(gè)類方法返回一個(gè)以缺省格式化方式初始化的日期/時(shí)間格式化程序。 可以根據(jù)需要用 applyPattern 方法修改格式化方式。
SimpleDateFormat函數(shù)的繼承關(guān)系:
java.lang.Object
|
+----java.text.Format
|
+----java.text.DateFormat
|
+----java.text.SimpleDateFormat
字母 | 日期或時(shí)間元素 | 表示 | 示例 |
---|---|---|---|
G
| Era 標(biāo)志符 | Text | AD
|
y
| 年 | Year | 1996 ; 96
|
M
| 年中的月份 | Month | July ; Jul ; 07
|
w
| 年中的周數(shù) | Number | 27
|
W
| 月份中的周數(shù) | Number | 2
|
D
| 年中的天數(shù) | Number | 189
|
d
| 月份中的天數(shù) | Number | 10
|
F
| 月份中的星期 | Number | 2
|
E
| 星期中的天數(shù) | Text | Tuesday ; Tue
|
a
| Am/pm 標(biāo)記 | Text | PM
|
H
| 一天中的小時(shí)數(shù)(0-23) | Number | 0
|
k
| 一天中的小時(shí)數(shù)(1-24) | Number | 24
|
K
| am/pm 中的小時(shí)數(shù)(0-11) | Number | 0
|
h
| am/pm 中的小時(shí)數(shù)(1-12) | Number | 12
|
m
| 小時(shí)中的分鐘數(shù) | Number | 30
|
s
| 分鐘中的秒數(shù) | Number | 55
|
S
| 毫秒數(shù) | Number | 978
|
z
| 時(shí)區(qū) | General time zone | Pacific Standard Time ; PST ; GMT-08:00
|
Z
| 時(shí)區(qū) | RFC 822 time zone | -0800 |
一個(gè)小例子,幫助更好的理解SimpleDataFormat

































