日期时间解析类 android.text.format.DateFormat

 日期时间解析类 ,该类位于android.text.format.DateFormat这个package中,该类提供了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.

  我们可能看到了第一个参数均为inFormat这是一个CharSequence接口的String类型,它提供了灵活的时间格式解析字符串描述,提示大家注意大小写要区分,如

   April 6, 1970 at 3:23am 例子,那么inFormat参数的写法和最终执行的结果如下对照,

下面就以Android123的CWJ生日为例子如下

"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"


用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小时制式



Constants

public static final char AM_PM
Since:  API Level 3

This designator indicates whether the HOUR field is before or after noon. The output is lower-case. Examples: a -> a or p aa -> am or pm

Constant Value: 97 (0x00000061)
public static final char CAPITAL_AM_PM
Since:  API Level 3

This designator indicates whether the HOUR field is before or after noon. The output is capitalized. Examples: A -> A or P AA -> AM or PM

Constant Value: 65 (0x00000041)
public static final char DATE
Since:  API Level 3

This designator indicates the day of the month. Examples for the 9th of the month: d -> 9 dd -> 09

Constant Value: 100 (0x00000064)
public static final char DAY
Since:  API Level 3

This designator indicates the name of the day of the week. Examples for Sunday: E -> Sun EEEE -> Sunday

Constant Value: 69 (0x00000045)
public static final char HOUR
Since:  API Level 3

This designator indicates the hour of the day in 12 hour format. Examples for 3pm: h -> 3 hh -> 03

Constant Value: 104 (0x00000068)

public static final char HOUR_OF_DAY
Since:  API Level 3

This designator indicates the hour of the day in 24 hour format. Example for 3pm: k -> 15 Examples for midnight: k -> 0 kk -> 00

Constant Value: 107 (0x0000006b)
public static final char MINUTE
Since:  API Level 3

This designator indicates the minute of the hour. Examples for 7 minutes past the hour: m -> 7 mm -> 07

Constant Value: 109 (0x0000006d)
public static final char MONTH
Since:  API Level 3

This designator indicates the month of the year Examples for September: M -> 9 MM -> 09 MMM -> Sep MMMM -> September

Constant Value: 77 (0x0000004d)
public static final char QUOTE
Since:  API Level 3

Text in the format string that should be copied verbatim rather that interpreted as formatting codes must be surrounded by the QUOTE character. If you need to embed a literal QUOTE character in the output text then use two in a row.

Constant Value: 39 (0x00000027)
public static final char SECONDS
Since:  API Level 3

This designator indicates the seconds of the minute. Examples for 7 seconds past the minute: s -> 7 ss -> 07

Constant Value: 115 (0x00000073)
public static final char TIME_ZONE
Since:  API Level 3

This designator indicates the offset of the timezone from GMT. Example for US/Pacific timezone: z -> -0800 zz -> PST

Constant Value: 122 (0x0000007a)
public static final char YEAR
Since:  API Level 3

This designator indicates the year. Examples for 2006 y -> 06 yyyy -> 2006

Constant Value: 121 (0x00000079)

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值