|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.smartgwt.client.util.DateUtil
public class DateUtil
Date related utility methods.
| Field Summary | |
|---|---|
static DateDisplayFormatter |
TO24HOURTIME
String will display with seconds in 24 hour time: [H]H:MM:SS. |
static DateDisplayFormatter |
TODATESTAMP
Date in the format <YYYYMMDD>T<HHMMSS>Z Example: 20051104T111001Z |
static DateDisplayFormatter |
TOEUROPEANSHORTDATE
Short date in format DD/MM/YYYY. Example: 4/11/2005 |
static DateDisplayFormatter |
TOEUROPEANSHORTDATETIME
Short date with time in format DD/MM/YYYY HH:MM Example: 4/11/2005 11:03 |
static DateDisplayFormatter |
TOJAPANSHORTDATE
Short date in format YYYY/MM/DD. Example: 2005/11/4 |
static DateDisplayFormatter |
TOJAPANSHORTDATETIME
Short date with time in format YYYY/MM/DD HH:MM Example: 2005/11/4 11:03 |
static DateDisplayFormatter |
TOLOCALESTRING
Default native browser 'toLocaleString()' implementation. |
static DateDisplayFormatter |
TONORMALDATE
Normal date format for the locale |
static DateDisplayFormatter |
TONORMALDATETIME
Normal datetime format for the locale |
static DateDisplayFormatter |
TOPADDED24HOURTIME
String will display with seconds, with a 2 digit hour in 24 hour format: HH:MM:SS. |
static DateDisplayFormatter |
TOPADDEDTIME
String will display with seconds, with a 2 digit hour and am/pm indicator: HH:MM:SS am|pm. |
static DateDisplayFormatter |
TOSERIALIZEABLEDATE
Date in the format YYYY-MM-DD HH:MM:SS Example: 2005-11-04 11:09:15 |
static DateDisplayFormatter |
TOSHORT24HOURTIME
String will have no seconds and be in 24 hour format: [H]H:MM.Example: 15:25 |
static DateDisplayFormatter |
TOSHORTPADDED24HOURTIME
String will have no seconds and will display with a 2 digit hour in 24 hour clock format: HH:MM.Examples: 15:25, 03:16 |
static DateDisplayFormatter |
TOSHORTPADDEDTIME
String will have no seconds and will display a 2 digit hour, in 12 hour clock format: HH:MM am|pm.Example: 03:25 pm |
static DateDisplayFormatter |
TOSHORTTIME
String will have no seconds and be in 12 hour format: [H]H:MM am|pm.Example: 3:25 pm |
static DateDisplayFormatter |
TOSTRING
Default native browser 'toString()' implementation. |
static DateDisplayFormatter |
TOTIME
String will display with seconds and am/pm indicator: [H]H:MM:SS am|pm. |
static DateDisplayFormatter |
TOUSSHORTDATE
Short date in format MM/DD/YYYY. Example: 11/4/2005 |
static DateDisplayFormatter |
TOUSSHORTDATETIME
Short date with time in format MM/DD/YYYY HH:MM Example: 11/4/2005 11:03 |
| Constructor Summary | |
|---|---|
DateUtil()
|
|
| Method Summary | |
|---|---|
static Date |
combineLogicalDateAndTime(Date date,
Date time)
Combine a logical date (a value appropriate for a DataSourceField of type "date") with a logical time (a value appropriate for a DataSourceField of type "time") into a datetime value (a value appropriate for a DataSourceField of type "datetime") |
static LogicalDate |
createLogicalDate(int year,
int month,
int date)
Create a new Date to represent a logical date value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,date type field}. |
static LogicalTime |
createLogicalTime(int hour,
int minute,
int second,
int millisecond)
Create a new Date object to represent a logical time value (rather than a specific datetime value), typically for display in a +link{DataSourceField.type,time type field}. |
static String |
format(Date date)
Format a date as a string according to the format specified by setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter). |
static String |
formatAsNormalDate(Date date)
Format a date as a string according to the format specified by setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter). |
static String |
formatAsShortDate(Date date)
Format a date as a string according to the format specified by setShortDateDisplayFormat(DateDisplayFormat) or
setShortDateDisplayFormatter(DateDisplayFormatter). |
static String |
formatAsShortDatetime(Date date)
Format a date as a string according to the format specified by setShortDatetimeDisplayFormat(DateDisplayFormat) or
setShortDatetimeDisplayFormatter(DateDisplayFormatter). |
static Date |
getAbsoluteDate(RelativeDate relativeDate)
Converts a RelativeDate to a concrete Date. |
static Date |
getAbsoluteDate(RelativeDate relativeDate,
Date baseDate,
RelativeDateRangePosition position)
Converts a RelativeDate to a concrete Date. |
static String |
getDefaultDateSeparator()
Returns the default date separator. |
static FiscalCalendar |
getFiscalCalendar()
Get the system wide com.cmartget.client.widgets.FiscalCalendar. |
static Date |
getFiscalStartDate(Date date,
FiscalCalendar fiscalCalendar)
Get the start date of the fiscal period in which the passed date exists. |
static Date |
getFiscalStartDate(Integer year,
FiscalCalendar fiscalCalendar)
Get the start date of the fiscal period for the passed year. |
static Integer |
getFiscalWeek(Date date,
FiscalCalendar fiscalCalendar)
Get the fiscal week in the period in which the passed date exists. |
static FiscalYear |
getFiscalYear(Date date,
FiscalCalendar fiscalCalendar)
Get the fiscal year object in which the passed date exists. |
static FiscalYear |
getFiscalYear(Integer year,
FiscalCalendar fiscalCalendar)
Get the fiscal year object for the passed year. |
static LogicalDate |
getLogicalDateOnly(Date date)
Get a logical date - a value appropriate for a DataSourceField of type "date" - from a datetime value (a value from a DataSourceField of type "datetime"). |
static LogicalTime |
getLogicalTimeOnly(Date date)
Get a logical time - a value appropriate for a DataSourceField of type "time" - from a datetime value (a value from a DataSourceField of type "datetime"). |
static String |
mapRelativeDateShortcut(String relativeDateShortcut)
|
static String |
mapRelativeDateShortcut(String relativeDateShortcut,
RelativeDateRangePosition position)
Converts a RelativeDate shortcut string such as "$today" to a RelativeDateString such as "+0D" |
static Date |
parseInput(String dateString)
Parse a formatted date string into a Date object. |
static void |
setAdjustForDST(boolean adjustForDST)
Determines whether, when formatting values of type datetime and time, the effect of Daylight Saving Time should be considered when computing offsets from UTC. |
static void |
setDateInputFormat(String inputFormat)
Sets up the default system-wide input format for strings being parsed into dates via SmartGWT utilities and components (see parseInput(String)). |
static void |
setDateInputFormatter(DateInputFormatter formatter)
Deprecated. in favor of setDateParser() |
static void |
setDateParser(DateParser parser)
Sets up a custom parsing function to use by default when converting dates or datetimes from formatted string values to Dates. |
static void |
setDefaultDateSeparator(String separator)
Sets a new default separator that will be used when formatting dates. |
static void |
setDefaultDisplayTimezone(String offset)
Globally sets the offset from UTC to use when formatting values of type datetime and time with standard display formatters. |
static void |
setFiscalCalendar(FiscalCalendar fiscalCalendar)
Set the system wide com.cmartget.client.widgets.FiscalCalendar for use when working with Dates. |
static void |
setNormalDateDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setNormalDateDisplayFormatter(DateDisplayFormatter). |
static void |
setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
Set the default formatter for date objects to the custom DateDisplayFormatter passed in. |
static void |
setNormalDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set the default datetime format for date objects to the DateDisplayFormat passed in. |
static void |
setNormalTimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default normal time formatting function. |
static void |
setShortDateDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setShortDateDisplayFormatter(DateDisplayFormatter). |
static void |
setShortDateDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short date formatting function. |
static void |
setShortDatetimeDisplayFormat(DateDisplayFormat format)
Deprecated. This method is deprecated in favor of setShortDatetimeDisplayFormatter(DateDisplayFormatter). |
static void |
setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short datetime formatting function. |
static void |
setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short time formatting function. |
static void |
setShowChooserFiscalYearPickers(boolean showFiscalYearPickers)
Should the Fiscal Year picker be displayed by default in all DateChoosers? |
static void |
setShowChooserWeekPickers(boolean showWeekPickers)
Should the Week picker be displayed by default in all DateChoosers? |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final DateDisplayFormatter TOSTRING
Fri Nov 04 2005
11:03:00 GMT-0800 (Pacific Standard Time)
public static final DateDisplayFormatter TOLOCALESTRING
Friday, November
04, 2005 11:03:00 AM
public static final DateDisplayFormatter TONORMALDATE
public static final DateDisplayFormatter TONORMALDATETIME
public static final DateDisplayFormatter TOUSSHORTDATE
11/4/2005
public static final DateDisplayFormatter TOUSSHORTDATETIME
11/4/2005 11:03
public static final DateDisplayFormatter TOEUROPEANSHORTDATE
4/11/2005
public static final DateDisplayFormatter TOEUROPEANSHORTDATETIME
4/11/2005 11:03
public static final DateDisplayFormatter TOJAPANSHORTDATE
2005/11/4
public static final DateDisplayFormatter TOJAPANSHORTDATETIME
2005/11/4 11:03
public static final DateDisplayFormatter TOSERIALIZEABLEDATE
2005-11-04 11:09:15
public static final DateDisplayFormatter TODATESTAMP
20051104T111001Z
public static final DateDisplayFormatter TOTIME
[H]H:MM:SS am|pm. 3:25:15
pm
public static final DateDisplayFormatter TO24HOURTIME
[H]H:MM:SS. 15:25:15
public static final DateDisplayFormatter TOPADDEDTIME
HH:MM:SS am|pm. 03:25:15 pm
public static final DateDisplayFormatter TOPADDED24HOURTIME
HH:MM:SS. 15:25:15, 03:16:45
public static final DateDisplayFormatter TOSHORTTIME
[H]H:MM am|pm.3:25 pm
public static final DateDisplayFormatter TOSHORT24HOURTIME
[H]H:MM.15:25
public static final DateDisplayFormatter TOSHORTPADDEDTIME
HH:MM am|pm.03:25 pm
public static final DateDisplayFormatter TOSHORTPADDED24HOURTIME
HH:MM.15:25, 03:16
| Constructor Detail |
|---|
public DateUtil()
| Method Detail |
|---|
public static void setDefaultDisplayTimezone(String offset)
If this method is never called, the default display timezone for times and datetimes will be derived from the native browser local timezone.
Note that by default daylight savings time adjustments (based on browser locale) may also be
applied when formatting datetimes.
setAdjustForDST(boolean) may be used to disable this adjustment.
offset - offset from UTC. This should be a string in the format +/-HH:MM for example "-08:00"public static void setAdjustForDST(boolean adjustForDST)
Note that setting this flag to true will have no effect unless you are in a locale that is observing Daylight Saving Time this year; this is because we rely on the browser for offset information, and browsers are only capable of returning local date and time information for the computer's current locale.
whether - time and datetimes should account for daylight savings time in this applicationpublic static void setDefaultDateSeparator(String separator)
separator - the date separatorpublic static String getDefaultDateSeparator()
@Deprecated public static void setNormalDateDisplayFormat(DateDisplayFormat format)
setNormalDateDisplayFormatter(DateDisplayFormatter).
format - the DateDisplayFormatpublic static void setNormalDatetimeDisplayFormatter(DateDisplayFormatter formatter)
format - the DateDisplayFormatterpublic static void setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
When writing custom date formatting and parsing logic, developers may find the
DateTimeFormat class helpful.
SmartGWT includes several built-in DateDisplayFormatters for common formats - see
DateDisplayFormatter for details.
Sample code :
DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() {
public String format(Date date) {
if(date == null) return null;
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy.MM.dd HH:mm:ss");
String format = dateFormatter.format(date);
return format;
}
});
formatter - the DateDisplayFormatter@Deprecated public static void setShortDateDisplayFormat(DateDisplayFormat format)
setShortDateDisplayFormatter(DateDisplayFormatter).
formatAsShortDate(Date)).
This method, together with setDefaultDateSeparator(String) provide support for most
standard "short date" formats. However if a custom format which doesn't match any of the specified
DateDisplayFormat types is required, a custom formatting function may be provided via
setShortDateDisplayFormatter(DateDisplayFormatter).
Note that the default short date format is initially set to DateDisplayFormat.TOUSSHORTDATE. This property
is commonly modified for localization of applications. See http://en.wikipedia.org/wiki/Date_format_by_country
for a useful overview of standard date formats per country.
format - the DateDisplayFormatpublic static void setShortDateDisplayFormatter(DateDisplayFormatter formatter)
formatAsShortDate(Date)).
If a custom short date formatter is applied, bear in mind that it will be applied by default when
editing date values, so the system will need to be able to parse an edited date string in this format
back to a live date object. Developers calling this method will therefore also commonly want to
apply custom parsing logic via setDateInputFormat(String) or setDateParser(DateParser).
When writing custom date formatting and parsing logic, developers may find the
DateTimeFormat class helpful.
SmartGWT includes several built-in DateDisplayFormatters for common formats - see
DateDisplayFormatter for details.
Sample code :
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
public String format(Date date) {
if(date == null) return null;
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
String format = dateFormatter.format(date);
return format;
}
});
formatter - the DateDisplayFormatter@Deprecated public static void setShortDatetimeDisplayFormat(DateDisplayFormat format)
setShortDatetimeDisplayFormatter(DateDisplayFormatter).
formatAsShortDatetime(Date)).
This method, together with setDefaultDateSeparator(String) provide support for most
standard "short date" formats. However if a custom format which doesn't match any of the specified
DateDisplayFormat types is required, a custom formatting function may be provided via
setShortDatetimeDisplayFormatter(DateDisplayFormatter).
Note that the default short datetime format is initially set to DateDisplayFormat.TOUSSHORTDATETIME.
This property is commonly modified for localization of applications. See http://en.wikipedia.org/wiki/Date_format_by_country
for a useful overview of standard date formats per country.
format - the DateDisplayFormatpublic static void setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
formatAsShortDatetime(Date)).
If a custom short datetime formatter is applied, bear in mind that it will be applied by default when
editing date values, so the system will need to be able to parse an edited date string in this format
back to a live date object. Developers calling this method will therefore also commonly want to
apply custom parsing logic via setDateInputFormat(String) or setDateParser(DateParser).
When writing custom date formatting and parsing logic, developers may find the
DateTimeFormat class helpful.
SmartGWT includes several built-in DateDisplayFormatters for common formats - see
DateDisplayFormatter for details.
formatter - the DateDisplayFormatter
public static LogicalDate createLogicalDate(int year,
int month,
int date)
See the docs for a discussion of the difference between
datetime field values and logical date field values, logical time field values.
year - month - date -
public static LogicalTime createLogicalTime(int hour,
int minute,
int second,
int millisecond)
See the docs for a discussion of the difference between
datetime field values and logical date field values, logical time field values.
hour - (0-23)minute - (0-59)second - (0-59)millisecond - (0-999)
public static Date parseInput(String dateString)
This calls the default parsing function used by SmartGWT components.
If setDateInputFormat(String) or setDateParser(DateParser)
has been specified it will be respected.
dateString - string to parse into a Date
public static String formatAsShortDate(Date date)
setShortDateDisplayFormat(DateDisplayFormat) or
setShortDateDisplayFormatter(DateDisplayFormatter).
This calls the standard date formatting function used by SmartGWT components to display short-formatted dates.
date -
public static String formatAsShortDatetime(Date date)
setShortDatetimeDisplayFormat(DateDisplayFormat) or
setShortDatetimeDisplayFormatter(DateDisplayFormatter).
This calls the standard date formatting function used by SmartGWT components to display short-formatted date-times.
date -
public static String format(Date date)
setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter).
This calls the standard date formatting function used by SmartGWT components to display short-formatted dates.
date -
public static String formatAsNormalDate(Date date)
setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter).
This calls the standard date formatting function used by SmartGWT components to display normal-formatted dates.
date -
public static void setDateInputFormatter(DateInputFormatter formatter)
DateUtil.setDateInputFormatter(new DateInputFormatter() {
public Date format(String dateString) {
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
Date date = dateFormatter.parse(dateString);
return date;
}
});
formatter - the DateInputFormatterpublic static void setDateParser(DateParser parser)
setShortDateDisplayFormat(DateDisplayFormat) or
setShortDateDisplayFormatter(DateDisplayFormatter) and
setShortDatetimeDisplayFormat(DateDisplayFormat) or
setShortDatetimeDisplayFormatter(DateDisplayFormatter) methods.
Note that the default date parsing logic already handles all standard short date formats, including
those formatted with custom separators. In most cases rather than applying an entirely custom
date parser method, desired behavior can be achieved via changing the
standard #setDateInputFormat(String),input format.
When writing custom date formatting and parsing logic, developers may find the
DateTimeFormat class helpful.
Sample code :
DateUtil.setDateParser(new DateParser() {
public Date parse(String dateString) {
final DateTimeFormat format = DateTimeFormat.getFormat("MMM d, yyyy");
Date date = format.parse(dateString);
return date;
}
});
Individual components may also override date formatting and parsing functions directly.
parser - public static void setDateInputFormat(String inputFormat)
parseInput(String)). This input format is respected when
parsing formatted strings to "date" or "datetime" type values.
This method takes a 3 character string like "MDY" indicating the
order of the Month, Day and Year components of date strings.
As an example - an input format of "MDY" would parse "01/02/1999" to Jan 2nd 1999
This standard parsing logic will also handle date-time strings such as "01/02/1999 08:45", or
"01/02/1999 16:21:05".
Notes:
#setShortDateDisplayFormat(DateDisplayFormat),short date display format. For
example if the short display format has been set to "toEuropeanShortDate" the input format will default
to "DMY".setDateParser().
inputFormat -
public static String mapRelativeDateShortcut(String relativeDateShortcut,
RelativeDateRangePosition position)
"$today" to a RelativeDateString such as "+0D"
relativeDateShortcut - shortcut string to convertposition - Are we interested in the start or end of the
// specified relative date? This applies to shortcuts which do not specify a specific
// moment (such as $today) - it does not apply to shortcuts which
// already specify a specific moment such as $startOfToday. If unspecified
// rangePosition is always assumed to be "start"
public static String mapRelativeDateShortcut(String relativeDateShortcut)
public static Date getAbsoluteDate(RelativeDate relativeDate)
public static Date getAbsoluteDate(RelativeDate relativeDate,
Date baseDate,
RelativeDateRangePosition position)
public static void setNormalTimeDisplayFormatter(DateDisplayFormatter formatter)
isc.Time.toTime() will return
a string formatted according to this formatter specification.
Note: this will be the standard time format used by SmartGWT components.
The initial default normal time display formatter is DateUtil.TOTIME.
SmartGWT includes several built-in DateDisplayFormatters for common formats - see
DateDisplayFormatter for details.
formatter - the DateDisplayFormatterpublic static void setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
isc.Time.toShortTime() will return
a string formatted according to this formatter specification.
Note: this will be the standard time format used by SmartGWT components.
The initial default normal time display formatter is DateUtil.TOSHORTTIME.
SmartGWT includes several built-in DateDisplayFormatters for common formats - see
DateDisplayFormatter for details.
formatter - the DateDisplayFormatterpublic static LogicalDate getLogicalDateOnly(Date date)
This method correctly takes into account the current display timezone
(see setDefaultDisplayTimezone()),, specifically, the returned Date
will reflect the day, month and year that appears when the datetime is rendered
by a SmartGWT component rather than the date values that would be returned by
Date.getDay() et al (which can differ, since getDay() uses the browser's local timezone).
For further background on date, time and datetime types, storage and transmission, see
com.smartgwt.client.docs.DateFormatAndStorage, this overview.
public static LogicalTime getLogicalTimeOnly(Date date)
This method correctly takes into account the current display timezone
(see setDefaultDisplayTimezone()),
specifically, the returned Date will
reflect the hour, minute and second that appears when the datetime
is rendered by a SmartGWT component rather than the time values that would be returned by
Date.getHours() et al (which can differ, since getHours() uses the browser's local timezone).
For further background on date, time and datetime types, storage and transmission, see the
com.smartgwt.client.docs.DateFormatAndStorage, this overview.
public static Date combineLogicalDateAndTime(Date date,
Date time)
This method correctly takes into account the current display timezone
(see setDefaultDisplayTimezone()), specifically, the returned datetime
value will show the same date and time as the passed date and time objects when rendered by
a SmartGWT component that has been configured with a field of type "datetime".
For further background on date, time and datetime types, storage
com.smartgwt.client.docs.DateFormatAndStorage, this overview.
date - time -
public static void setFiscalCalendar(FiscalCalendar fiscalCalendar)
com.cmartget.client.widgets.FiscalCalendar for use when working with Dates.
fiscalCalendar - the FiscalCalendarpublic static FiscalCalendar getFiscalCalendar()
com.cmartget.client.widgets.FiscalCalendar.
public static Date getFiscalStartDate(Date date,
FiscalCalendar fiscalCalendar)
public static Date getFiscalStartDate(Integer year,
FiscalCalendar fiscalCalendar)
public static FiscalYear getFiscalYear(Date date,
FiscalCalendar fiscalCalendar)
public static FiscalYear getFiscalYear(Integer year,
FiscalCalendar fiscalCalendar)
public static Integer getFiscalWeek(Date date,
FiscalCalendar fiscalCalendar)
public static void setShowChooserFiscalYearPickers(boolean showFiscalYearPickers)
public static void setShowChooserWeekPickers(boolean showWeekPickers)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||