|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.i18n.Format
net.rim.device.api.i18n.DateFormat
net.rim.device.api.i18n.SimpleDateFormat
public class SimpleDateFormat
Formats and parses dates in a locale-sensitive manner.
Formatting is done employing a user-defined pattern string constructed some or all of the following symbols:
Symbol | Meaning | Presentation | Example |
---|---|---|---|
y | year | (Number) | 1996 |
M | month in year | (Text & Number) | July & 07 |
d | day in month | (Number) | 10 |
h | hour in am/pm (1~12) | (Number) | 12 |
H | hour in day (0~23) | (Number) | 0 |
m | minute in hour | (Number) | 30 |
s | second in minute | (Number) | 55 |
S | millisecond | (Number) | 978 |
E | day in week | (Text) | Tuesday |
a | am/pm marker | (Text) | PM |
z | time zone | (Text) | Pacific Standard Time |
' | escape for text | (Delimiter) | |
'' | single quote | (Literal) | ' |
The following are not implemented due to CLDC limitations in the Calendar
class;
These will all insert "NI":
Symbol | Meaning | Presentation | Example |
---|---|---|---|
G | era designator | (Text) | CE |
D | day in year | (Number) | 189 |
F | day of week in month | (Number) | 2 (2nd Wed in July) |
w | week in year | (Number) | 27 |
W | week in month | (Number) | 2 |
Any non-alphabetic symbols in the pattern are passed on as if these were quoted text.
Most patterns require or are affected by a length.
Symbol | Pattern | Example | Example |
---|---|---|---|
y | yyyy | 1996 | |
yy | 96 | ||
M | M | 7 | |
MM | 07 | ||
MMM | Jul | ||
MMMM | July | ||
d | d | 9 | |
dd | 09 | ||
h | h | 9 | 2 |
hh | 09 | 02 | |
H | H | 9 | 14 |
HH | 09 | 14 | |
m | m | 7 | 30 |
mm | 07 | 30 | |
s | s | 3 | 55 |
ss | 03 | 55 | |
S | S | 978 | 4 |
SS | 978 | 04 | |
SSS | 978 | 004 | |
E | E, EE, EEE | Tue | |
EEEE | Tuesday | ||
a | a | p | |
aa | PM | ||
z | z | Pacific Standard Time |
Compatible with java.text.SimpleDateFormat in Java's standard edition.
Field Summary |
---|
Fields inherited from class net.rim.device.api.i18n.DateFormat |
---|
AM_PM_FIELD, DATETIME_DEFAULT, DATE_DEFAULT, DATE_FIELD, DATE_FULL, DATE_LONG, DATE_MEDIUM, DATE_SHORT, DAY_OF_WEEK_FIELD, ERA_FIELD, GUID_DATE_FORMAT_CHANGED, HOUR_FIELD, HOUR_OF_DAY_FIELD, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, SECOND_FIELD, TIMEZONE_FIELD, TIME_DEFAULT, TIME_FULL, TIME_LONG, TIME_MEDIUM, TIME_SHORT, YEAR_FIELD |
Constructor Summary | ||
---|---|---|
SimpleDateFormat(int style)
Constructs a SimpleDateFormat using the given style and the default date format symbols for the default locale. |
||
SimpleDateFormat(String pattern)
Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default locale. |
||
SimpleDateFormat(String pattern,
Locale locale)
Constructs a new SimpleDateFormat instance with provided pattern string. |
Method Summary | ||
---|---|---|
void |
applyPattern(int style)
Applies a date/time format style to this formatter. |
|
void |
applyPattern(String pattern)
Applies a date/time pattern string to this formatter. |
|
StringBuffer |
format(Calendar calendar,
StringBuffer toAppendTo_o,
FieldPosition pos_io)
Retrieves formatted string representation of calendar object. |
|
int[] |
getFields()
Retrieves ordered list of fields. |
|
String |
toPattern()
Returns a pattern string describing this formatter's current format style. |
Methods inherited from class net.rim.device.api.i18n.DateFormat |
---|
format, formatLocal, formatLocal, getInstance |
Methods inherited from class net.rim.device.api.i18n.Format |
---|
format |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleDateFormat(int style)
See DateFormat
for the date/time format styles you should
choose from.
style
- Date/time format style for this formatterpublic SimpleDateFormat(String pattern)
Note: Instead of building a simple date formatter
with this constructor, use DateFormat.getInstance(int)
to retrieve the
simple formatter in the particular style you want.
pattern
- the pattern to use when formatting dates and times.
NullPointerException
- if any parameter is null.DateFormat
public SimpleDateFormat(String pattern, Locale locale)
pattern
- the pattern to use when formatting dates and times.locale
- the locale whose symbols to use.
NullPointerException
- if any parameter is null.DateFormat
Method Detail |
---|
public void applyPattern(int style)
See DateFormat
for the date/time format styles you should
choose from.
style
- Date/time format style for this formatter.public void applyPattern(String pattern)
pattern
- Pattern string to use with this formatter (see this
class's description for the supported characters in a pattern string).public StringBuffer format(Calendar calendar, StringBuffer toAppendTo_o, FieldPosition pos_io)
This method uses this formatter's current style to format the date contained in your calendar object, placing the result in a string buffer.
format
in class DateFormat
calendar
- Calendar object containing the date to format.toAppendTo_o
- String buffer to hold the formatted results.pos_io
- If not null, this method invokes SimpleDateFormat.getFields()
and
sets the begin/end for the field during formatting.
public int[] getFields()
getFields
in class Format
public String toPattern()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.