Android DateFormat
2012-07-17 16:46
232 查看
Format the time:
For Detail ,consult http://developer.android.com/reference/android/text/format/DateFormat.html
java.text.DateFormat
java.text.format.DateFormat
For the month of September:
M -> 9
MM -> 09
MMM -> Sep
MMMM -> September
For 7 minutes past the hour:
m -> 7
mm -> 07
mmm -> 007
mmmm -> 0007
Examples for April 6, 1970 at 3:23am:
"MM/dd/yy h:mmaa" -> "04/06/70 3:23am"
"MMM dd, yyyy h:mmaa" -> "Apr 6, 1970 3:23am"
"MMMM dd, yyyy h:mmaa" -> "April 6, 1970 3:23am"
"E, MMMM dd, yyyy h:mmaa" -> "Mon, April 6, 1970 3:23am&
"EEEE, MMMM dd, yyyy h:mmaa" -> "Monday, April 6, 1970 3:23am"
"'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"
SimpleDateFormat For detail,consult http://developer.android.com/reference/java/text/SimpleDateFormat.html
The number of consecutive copies (the "count") of a pattern character further influences the format.
Text if the count is 4 or more, use the full form; otherwise use a short or abbreviated form if one exists. So
Number the count is the minimum number of digits. Shorter values are zero-padded to this width, longer values overflow this width.
Years are handled specially:
Fractional seconds are also handled specially: they're zero-padded on the right.
Text/Number: if the count is 3 or more, use text; otherwise use a number. So
The two pattern characters
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String date = sDateFormat.format(new java.util.Date());
For Detail ,consult http://developer.android.com/reference/android/text/format/DateFormat.html
java.text.DateFormat
java.text.format.DateFormat
For the month of September:
M -> 9
MM -> 09
MMM -> Sep
MMMM -> September
For 7 minutes past the hour:
m -> 7
mm -> 07
mmm -> 007
mmmm -> 0007
Examples for April 6, 1970 at 3:23am:
"MM/dd/yy h:mmaa" -> "04/06/70 3:23am"
"MMM dd, yyyy h:mmaa" -> "Apr 6, 1970 3:23am"
"MMMM dd, yyyy h:mmaa" -> "April 6, 1970 3:23am"
"E, MMMM dd, yyyy h:mmaa" -> "Mon, April 6, 1970 3:23am&
"EEEE, MMMM dd, yyyy h:mmaa" -> "Monday, April 6, 1970 3:23am"
"'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"
SimpleDateFormat For detail,consult http://developer.android.com/reference/java/text/SimpleDateFormat.html
Symbol | Meaning | Presentation | Example |
D | day in year | (Number) | 189 |
E | day of week | (Text) | Tuesday |
F | day of week in month | (Number) | 2 (2nd Wed in July) |
G | era designator | (Text) | AD |
H | hour in day (0-23) | (Number) | 0 |
K | hour in am/pm (0-11) | (Number) | 0 |
L | stand-alone month | (Text/Number) | July / 07 |
M | month in year | (Text/Number) | July / 07 |
S | fractional seconds | (Number) | 978 |
W | week in month | (Number) | 2 |
Z | time zone (RFC 822) | (Timezone) | -0800 |
a | am/pm marker | (Text) | PM |
c | stand-alone day of week | (Text/Number) | Tuesday / 2 |
d | day in month | (Number) | 10 |
h | hour in am/pm (1-12) | (Number) | 12 |
k | hour in day (1-24) | (Number) | 24 |
m | minute in hour | (Number) | 30 |
s | second in minute | (Number) | 55 |
w | week in year | (Number) | 27 |
y | year | (Number) | 2010 |
z | time zone | (Timezone) | Pacific Standard Time |
' | escape for text | (Delimiter) | 'Date=' |
'' | single quote | (Literal) | 'o''clock' |
Text if the count is 4 or more, use the full form; otherwise use a short or abbreviated form if one exists. So
zzzzmight give
Pacific Standard Timewhereas
zmight give
PST. Note that the count does not specify the exact width of the field.
Number the count is the minimum number of digits. Shorter values are zero-padded to this width, longer values overflow this width.
Years are handled specially:
yytruncates to the last 2 digits, but any other number of consecutive
ys does not truncate. So where
yyyyor
ymight give
2010,
yywould give
10.
Fractional seconds are also handled specially: they're zero-padded on the right.
Text/Number: if the count is 3 or more, use text; otherwise use a number. So
MMmight give
07while
MMMgives
July.
The two pattern characters
Land
care ICU-compatible extensions, not available in the RI. These are necessary for correct localization in languages such as Russian that distinguish between, say, "June" and "June 2010".
yyyy-MM-dd 1970-01-01 yyyy-MM-dd HH:mm 1969-12-3116:00 yyyy-MM-dd HH:mm 1970-01-0100:00 yyyy-MM-dd HH:mmZ 1969-12-3116:00-0800 yyyy-MM-dd HH:mmZ 1970-01-0100:00+0000 yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-3116:00:00.000-0800 yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-0100:00:00.000+0000 yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800 yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000
相关文章推荐
- Android - SimpleDateFormat 详解
- Android SimpleDateFormat的使用
- android-Date 与 DateFormat 与 Calendar
- Android下setLatestEventInfo警告、Handler警告、SimpleDateFormat警告
- Android - SimpleDateFormat 详解
- 获取android中的 SimpleDateFormat——获取当前时间
- android.text.DateFormat的使用
- Android SimapleDateFormat 日期格式的转换方法
- Android SimpleDateFormat转换时间 12,24时间格式
- [置顶] Android 时间、日期处理 DateUtils、SystemClock、DateFormat
- 解决Android中Handler警告、SimpleDateFormat警告、"String".toUpperCase()警告
- Android Util Class:TextUtils +DateFormat
- android 利用SimpleDateFormat格式化时间不准确的问题
- 解决Android中Handler警告、SimpleDateFormat警告、"String".toUpperCase()警告
- Android下setLatestEventInfo警告、Handler警告、SimpleDateFormat警告http://www.piaoyi.org/mobile-app/Android-se
- 【转】Android SimpleDateFormat转换时间 12,24时间格式
- 解决Android中Handler警告、SimpleDateFormat警告、"String".toUpperCase()警告
- 解决Android中Handler警告、SimpleDateFormat警告、"String".toUpperCase()警告
- android 利用SimpleDateFormat格式化时间不准确的问题
- Android开发中setLatestEventInfo、Handler、SimpleDateFormat警告解决办法