日期時間解析類 android.text.format.DateFormat

來源:互聯網
上載者:User

 日期時間解析類 ,該類位於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_PMSince: 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_PMSince: 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 DATESince: 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 DAYSince: 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 HOURSince: 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_DAYSince: 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 MINUTESince: 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 MONTHSince: 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 QUOTESince: 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 SECONDSSince: 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_ZONESince: 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 YEARSince: API Level 3

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

Constant Value: 121 (0x00000079)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.