public class DateFormats
extends java.lang.Object
Constructor and Description |
---|
DateFormats() |
Modifier and Type | Method and Description |
---|---|
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.
|
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 timejava.text.ParseException
Copyright © 2005-2011 Potix Corporation. All Rights Reserved.