该类提供了Java中的三种时间对象,提示大家下面三种方法为静态可以直接调用,如下:
final static CharSequence format(CharSequence inFormat, Date inDate) //传入Date对象
Given a format string and a Date object, returns a CharSequence containing the requested date.
final static CharSequence format(CharSequence inFormat, Calendar inDate) //Calendar对象
Given a format string and a Calendar object, returns a CharSequence containing the requested date.
final static CharSequence format(CharSequence inFormat, long inTimeInMillis) //long对象
Given a format string and a time in milliseconds since Jan 1, 1970 GMT, returns a CharSequence containing the requested date.
在CrimeFragment.java中,我们加入以下代码来格式化日期
注意,我们可以格局需要来设定日期的格式模板,主要模板如下:
"MM/dd/yy h:mmaa" -> "11/03/87 11:23am"
"MMM dd, yyyy h:mmaa" -> "Nov 3, 1987 11:23am"
"MMMM dd, yyyy h:mmaa" -> "November 3, 1987 11:23am"
"E, MMMM dd, yyyy h:mmaa" -> "Tues , November 3, 1987 11:23am"
"EEEE, MMMM dd, yyyy h:mmaa" -> "Tues day, Nov 3, 1987 11:23am"
"YYYY年MM月dd日,kk:mm" -> 2014年09月30日,11:23
用24小时制:
"EEEE, MMMM dd, yyyy kk:mm" -> "Tues day, Nov 3, 1987 23:23"
其中:12小时制 :hh; 24小时制: kk,如果用 SimpleDateFormat ,则为: hh; HH
android.text.format.DateFormat类的static boolean is24HourFormat(Context context)方法可以用来判断当前系统时间是否为24小时制式