Android日期格式化
来源:互联网 发布:数据对比分析软件 编辑:程序博客网 时间:2024/05/17 06:28
Symbol Meaning Presentation Example Gera designator(Text)ADyyear(Number)1996Mmonth in year(Text & Number)July & 07dday in month(Number)10hhour in am/pm (1˜12)(Number)12Hhour in day (0˜23)(Number)0mminute in hour(Number)30ssecond in minute(Number)55Sfractional second(Number)978Eday of week(Text)TuesdayDday in year(Number)189Fday of week in month(Number)2 (2nd Wed in July)wweek in year(Number)27Wweek in month(Number)2aam/pm marker(Text)PMkhour in day (1˜24)(Number)24Khour in am/pm (0˜11)(Number)0ztime zone(Text)Pacific Standard TimeZtime zone (RFC 822)(Number)-0800vtime zone (generic)(Text)Pacific TimeVtime zone (location)(Text)United States (Los Angeles)'escape for text(Delimiter)'Date='''single quote(Literal)'o''clock'
接下来,我们再看下面这段话The count of pattern letters determines the format:
(Text): 4 or more pattern letters → use the full form, less than 4 pattern letters → use a short or abbreviated form if one exists.
(Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the year will be truncated to 2 digits. (if "yyyy" produces "1997", "yy" produces "97".) Unlike other fields, fractional seconds are padded on the right with zero.
(Text & Number): 3 or over, use text, otherwise use number.Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.
A pattern containing any invalid pattern letter will result in an exception thrown during formatting or parsing.
什么意思,总结起来很简单,就是y代表年,yy代表96年格式,yyyy代表1996年格式。我们用文档中的例子来看,Format Pattern Result -------------- ------- "yyyy.MM.dd G 'at' HH:mm:ss vvvv" → 1996.07.10 AD at 15:08:56 Pacific Time "EEE, MMM d, ''yy" → Wed, July 10, '96 "h:mm a" → 12:08 PM "hh 'o''clock' a, zzzz" → 12 o'clock PM, Pacific Daylight Time "K:mm a, vvv" → 0:00 PM, PT "yyyyy.MMMMM.dd GGG hh:mm aaa" → 01996.July.10 AD 12:08 PM
/** * 默认格式输出 */ SimpleDateFormat f = new SimpleDateFormat(); String format = f.format(new Date()); Log.i("默认格式", format); /** * yyyy-MM-dd HH:mm */ SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String format2 = f2.format(new Date()); Log.i("yyyy-MM-dd HH:mm", format2); /** * yyyy年MM月dd日 HH时mm分ss秒 */ SimpleDateFormat f3 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); String format3 = f3.format(new Date()); Log.i("yyyy年MM月dd日 HH时mm分ss秒", format3); /** * yyyy年MM月dd日 HH时mm分ss秒转成Date形式 */ SimpleDateFormat f4 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); try { Date date = f4.parse(format3); Log.i("yyyy年MM月dd日 HH时mm分ss秒转成Date", date.toString()); } catch (ParseException e) { e.printStackTrace(); }
- Android 格式化日期
- Android开发:日期格式化
- Android - 格式化显示日期
- Android 日期格式化
- android日期格式化
- Android日期格式化
- Android开发:日期格式化
- android--笔记--格式化日期字符串
- Android 获取日期并格式化
- Android 日期信息及其格式化
- Android的日期时间格式化
- 【Android】格式化日期 android.text.format.DateFormat
- android格式化日期与时间戳学习
- 日期格式化 android.text.format.DateFormat
- android 获取日期/时间格式化及注意
- 日期格式化 android.text.format.DateFormat
- android中时间 和 日期 格式化显示
- android时间日期随系统格式化输出
- HDU 3336-Count the string
- Java基础Math函数使用
- java开发工程师需求
- 嘉兴培训第二天——第一堂课
- Python 闭包
- Android日期格式化
- Java基础之While循环
- ZQUOJ1336最小生成树(MST)之Kruskal
- 那些游戏开发牛人的博客和IT学习网站
- scala学习笔记
- Java基础泛型Static方法
- Insert Interval
- ZQUOJ1335最小生成树(MST)之Prim
- 和java的DES/ECB/PKCS5Padding相同的objc实现方式