java.lang.Object | |
↳ | android.text.format.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"
"'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
char | AM_PM | This designator indicates whether the HOUR field is before
or after noon. |
|||||||||
char | CAPITAL_AM_PM | This designator indicates whether the HOUR field is before
or after noon. |
|||||||||
char | DATE | This designator indicates the day of the month. | |||||||||
char | DAY | This designator indicates the name of the day of the week. | |||||||||
char | HOUR | This designator indicates the hour of the day in 12 hour format. | |||||||||
char | HOUR_OF_DAY | This designator indicates the hour of the day in 24 hour format. | |||||||||
char | MINUTE | This designator indicates the minute of the hour. | |||||||||
char | MONTH | This designator indicates the month of the year Examples for September: M -> 9 MM -> 09 MMM -> Sep MMMM -> September | |||||||||
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. |
|||||||||
char | SECONDS | This designator indicates the seconds of the minute. | |||||||||
char | TIME_ZONE | This designator indicates the offset of the timezone from GMT. | |||||||||
char | YEAR | This designator indicates the year. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Given a format string and a Date object, returns a CharSequence containing
the requested date.
| |||||||||||
Given a format string and a Calendar object, returns a CharSequence
containing the requested date.
| |||||||||||
Given a format string and a time in milliseconds since Jan 1, 1970 GMT, returns a
CharSequence containing the requested date.
| |||||||||||
Returns a DateFormat object that can format the date according
to the current user preference.
| |||||||||||
Gets the current date format stored as a char array.
| |||||||||||
Returns a DateFormat object that can format the date
in long form (such as December 31, 1999) based on user preference.
| |||||||||||
Returns a DateFormat object that can format the date
in medium form (such as Dec.
| |||||||||||
Returns a DateFormat object that can format the time according
to the current user preference.
| |||||||||||
Returns true if user preference is set to 24-hour format.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
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
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
This designator indicates the day of the month. Examples for the 9th of the month: d -> 9 dd -> 09
This designator indicates the name of the day of the week. Examples for Sunday: E -> Sun EEEE -> Sunday
This designator indicates the hour of the day in 12 hour format. Examples for 3pm: h -> 3 hh -> 03
This designator indicates the hour of the day in 24 hour format. Example for 3pm: k -> 15 Examples for midnight: k -> 0 kk -> 00
This designator indicates the minute of the hour. Examples for 7 minutes past the hour: m -> 7 mm -> 07
This designator indicates the month of the year Examples for September: M -> 9 MM -> 09 MMM -> Sep MMMM -> September
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.
This designator indicates the seconds of the minute. Examples for 7 seconds past the minute: s -> 7 ss -> 07
This designator indicates the offset of the timezone from GMT. Example for US/Pacific timezone: z -> -0800 zz -> PST
This designator indicates the year. Examples for 2006 y -> 06 yyyy -> 2006
Given a format string and a Date object, returns a CharSequence containing the requested date.
inFormat | the format string, as described in DateFormat |
---|---|
inDate | the date to format |
Given a format string and a Calendar object, returns a CharSequence containing the requested date.
inFormat | the format string, as described in DateFormat |
---|---|
inDate | the date to format |
Given a format string and a time in milliseconds since Jan 1, 1970 GMT, returns a CharSequence containing the requested date.
inFormat | the format string, as described in DateFormat |
---|---|
inTimeInMillis | in milliseconds since Jan 1, 1970 GMT |
Returns a DateFormat object that can format the date according to the current user preference.
context | the application context |
---|
Returns a DateFormat object that can format the date in long form (such as December 31, 1999) based on user preference.
context | the application context |
---|
Returns a DateFormat object that can format the date in medium form (such as Dec. 31, 1999) based on user preference.
context | the application context |
---|
Returns a DateFormat object that can format the time according to the current user preference.
context | the application context |
---|
Returns true if user preference is set to 24-hour format.
context | the context to use for the content resolver |
---|