|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.text.DateFormats
public class DateFormats
DateFormat relevant utilities.
Constructor Summary | |
---|---|
DateFormats()
|
Method Summary | |
---|---|
static java.lang.String |
format(java.util.Date d,
boolean dateOnly)
Formats a Date object based on the current Locale and the default date format ( DateFormat.DEFAULT . |
static java.lang.String |
getDateFormat(int style,
java.util.Locale locale,
java.lang.String defaultFormat)
Returns the current date format; never null. |
static java.lang.String |
getDateTimeFormat(int dateStyle,
int timeStyle,
java.util.Locale locale,
java.lang.String defaultFormat)
Returns the current date/time format; never null. |
static DateFormatInfo |
getLocalFormatInfo()
Returns the info of date/time format for the current thread, or null if not set. |
static java.lang.String |
getTimeFormat(int style,
java.util.Locale locale,
java.lang.String defaultFormat)
Returns the current time format; never null. |
static java.util.Date |
parse(java.lang.String s,
boolean dateOnly)
Parses a string, that is formatted by format(java.util.Date, boolean) , to a date. |
static DateFormatInfo |
setLocalFormatInfo(DateFormatInfo info)
Sets the info of date/time format for the current thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DateFormats()
Method Detail |
---|
public static DateFormatInfo setLocalFormatInfo(DateFormatInfo info)
When Invoking this method under a thread, remember to clean up the setting upon completing each request.
DateFormatInfo old = DateFormats.setLocalFormatFormatInfo(info);
try {
...
} finally {
DateFormats.setLocalFormatInfo(old);
}
info
- the format info. It could be null (and the JVM's default
is used).
public static DateFormatInfo getLocalFormatInfo()
public static java.lang.String getDateFormat(int style, java.util.Locale locale, java.lang.String defaultFormat)
If a format info is set by setLocalFormatInfo(org.zkoss.text.DateFormatInfo)
,
DateFormatInfo.getDateFormat(int, java.util.Locale)
of the info will be called first.
If no info is set or the info returns null,
java.text.DateFormat.getDateInstance(style, locale)
will be called instead.
If no format is found and the value of defaultFormat
is not null,
defaultFormat
will be returned.
Otherwise, "M/d/yy" is returned.
style
- the giving formatting style. For example,
DateFormat.SHORT
for "M/d/yy" in the US locale.locale
- the locale. If null, Locales.getCurrent()
is assumed.defaultFormat
- the default format. It is used if no default
format. If null, "M/d/yy" is assumed.public static final java.lang.String getTimeFormat(int style, java.util.Locale locale, java.lang.String defaultFormat)
If a format info is set by setLocalFormatInfo(org.zkoss.text.DateFormatInfo)
,
DateFormatInfo.getTimeFormat(int, java.util.Locale)
of the info will be called first.
If no info is set or the info returns null,
java.text.DateFormat.getTimeInstance(style, locale)
will be called instead.
If no format is found and the value of defaultFormat
is not null,
defaultFormat
will be returned.
Otherwise, "h:mm a" is returned.
style
- the giving formatting style. For example,
DateFormat.SHORT
for "h:mm a" in the US locale.locale
- the locale. If null, Locales.getCurrent()
is assumed.defaultFormat
- the default format. It is used if no default
format. If null, "h:mm a" is assumed.public static final java.lang.String getDateTimeFormat(int dateStyle, int timeStyle, java.util.Locale locale, java.lang.String defaultFormat)
If a format info is set by setLocalFormatInfo(org.zkoss.text.DateFormatInfo)
,
DateFormatInfo.getDateTimeFormat(int, int, java.util.Locale)
of the info will be called first.
If no info is set or the info returns null,
java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale)
will be called instead.
If no format is found and the value of defaultFormat
is not null,
defaultFormat
will be returned.
Otherwise, "M/d/yy h:mm a" is returned.
dateStyle
- the giving formatting style. For example,
DateFormat.SHORT
for "M/d/yy" in the US locale.timeStyle
- the giving formatting style. For example,
DateFormat.SHORT
for "h:mm a" in the US locale.locale
- the locale. If null, Locales.getCurrent()
is assumed.public static final java.lang.String format(java.util.Date d, boolean dateOnly)
DateFormat.DEFAULT
.
dateOnly
- indicates whether to show only date; false to show
both date and timepublic static final java.util.Date parse(java.lang.String s, boolean dateOnly) throws java.text.ParseException
format(java.util.Date, boolean)
, to a date.
It assumes the current locale is Locales.getCurrent()
.
dateOnly
- indicates whether to show only date; false to show
both date and time
java.text.ParseException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |