English | Site Directory

Android - An Open Handset Alliance Project

android.util
public class

android.util.DateFormat

java.lang.Object
android.util.DateFormat

Utility class for producing strings with formatted date/time.

This class takes as inputs a format string and a representation of a date/time. The format string controls how the output is generated.

Formatting characters may be repeated in order to get more detailed representations of that field. For instance, the format character 'M' is used to represent the month. Depending on how many times that character is repeated you get a different representation.

For the month of September:
M -> 9
MM -> 09
MMM -> Sep
MMMM -> September

The effects of the duplication vary depending on the nature of the field. See the notes on the individual field formatters for details. For purely numeric fields such as HOUR adding more copies of the designator will zero-pad the value to that number of characters.

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"
"'Best day evar: 'M/d/yy" -> "Best day evar: 4/6/70"

Summary

Constants

      Value  
char  AM_PM  This designator indicates whether the HOUR field is before or after noon.  97  0x00000061 
char  CAPITAL_AM_PM  This designator indicates whether the HOUR field is before or after noon.  65  0x00000041 
char  DATE  This designator indicates the day of the month.  100  0x00000064 
char  DAY  This designator indicates the name of the day of the week.  69  0x00000045 
char  HOUR  This designator indicates the hour of the day in 12 hour format.  104  0x00000068 
char  HOUR_OF_DAY  This designator indicates the hour of the day in 24 hour format.  107  0x0000006b 
char  MINUTE  This designator indicates the minute of the hour.  109  0x0000006d 
char  MONTH  This designator indicates the month of the year Examples for September: M -> 9 MM -> 09 MMM -> Sep MMMM -> September   77  0x0000004d 
char  QUOTE  Text in the format string that should be copied verbatim rather that interpreted as formatting codes must be surrounded by the QUOTE character.  39  0x00000027 
char  SECONDS  This designator indicates the seconds of the minute.  115  0x00000073 
char  TIME_ZONE  This designator indicates the offset of the timezone from GMT.  122  0x0000007a 
char  YEAR  This designator indicates the year.  121  0x00000079 

Public Constructors

          DateFormat()

Public Methods

    final  static  CharSequence  format(CharSequence inFormat, Date inDate)
    final  static  CharSequence  format(CharSequence inFormat, Calendar inDate)
    final  static  CharSequence  format(CharSequence inFormat, long inTimeInMillis)
Methods inherited from class java.lang.Object

Details

Constants

public static final char AM_PM

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

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

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

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

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

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

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

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

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

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

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

This designator indicates the year. Examples for 2006 y -> 06 yyyy -> 2006
Constant Value: 121 (0x00000079)

Public Constructors

public DateFormat()

Public Methods

public static final CharSequence format(CharSequence inFormat, Date inDate)

public static final CharSequence format(CharSequence inFormat, Calendar inDate)

public static final CharSequence format(CharSequence inFormat, long inTimeInMillis)

Build m5-rc15i - 10 Jun 2008 13:54