public class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
DateUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
autoDetectFormats()
Use the GWT LocaleInfo class to auto-detect the various formats for dates and times.
|
static java.util.Date |
combineLogicalDateAndTime(java.util.Date date,
java.util.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 int |
compareDates(java.util.Date date1,
java.util.Date date2)
Compare two dates; returns 0 if equal, -1 if the first date is greater (later), or 1 if the second date is greater.
|
static int |
compareLogicalDates(java.util.Date date1,
java.util.Date date2)
Compare two dates, normalizing out the time elements so that only the date elements are considered; returns 0 if equal,
-1 if the first date is greater (later), or 1 if the second date is greater.
|
static java.util.Date |
create()
Create a new
Date object - synonym for new Date(arguments) |
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 java.lang.String |
format(java.util.Date date)
Format a date as a string according to the format specified by
setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
formatAsNormalDate(java.util.Date date)
Format a date as a string according to the format specified by
setNormalDateDisplayFormat(DateDisplayFormat) or
setNormalDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
formatAsShortDate(java.util.Date date)
Format a date as a string according to the format specified by
setShortDateDisplayFormat(DateDisplayFormat) or
setShortDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
formatAsShortDatetime(java.util.Date date)
Format a date as a string according to the format specified by
setShortDatetimeDisplayFormat(DateDisplayFormat) or
setShortDatetimeDisplayFormatter(DateDisplayFormatter) . |
static java.util.Date |
getAbsoluteDate(RelativeDate relativeDate)
Converts a RelativeDate to a concrete Date.
|
static java.util.Date |
getAbsoluteDate(RelativeDate relativeDate,
java.util.Date baseDate,
RelativeDateRangePosition position)
Converts a RelativeDate to a concrete Date.
|
static java.lang.String |
getDefaultDateSeparator()
Returns the default date separator.
|
static int |
getFirstDayOfWeek()
Returns the global attribute that dictates which day should be treated as the first day of the week in calendars and
date calculations.
|
static FiscalCalendar |
getFiscalCalendar()
Returns the global
FiscalCalendar object representing the start month
and date of the fiscal year in the current locale. |
static java.util.Date |
getFiscalStartDate(java.util.Date date)
Returns the start date of the fiscal year for the passed date.
|
static java.util.Date |
getFiscalStartDate(java.util.Date date,
FiscalCalendar fiscalCalendar)
Returns the start date of the fiscal year for the passed date.
|
static java.util.Date |
getFiscalStartDate(java.lang.Integer year,
FiscalCalendar fiscalCalendar)
Get the start date of the fiscal period for the passed year.
|
int |
getFiscalWeek()
Returns the fiscal week number of the current date, according to the global
FiscalCalendar . |
static int |
getFiscalWeek(java.util.Date date)
Returns a date's week-number, according to the fiscal calendar
|
static int |
getFiscalWeek(java.util.Date date,
FiscalCalendar fiscalCalendar)
Returns a date's week-number, according to the fiscal calendar
|
int |
getFiscalWeek(FiscalCalendar fiscalCalendar)
Returns the fiscal week number of the current date, according to the global
FiscalCalendar . |
FiscalYear |
getFiscalYear()
Returns the
FiscalYear object appropriate for the the current date, according to the
FiscalCalendar . |
static FiscalYear |
getFiscalYear(java.util.Date date)
Returns the
FiscalYear object for the fiscal year in which the passed date exists. |
static FiscalYear |
getFiscalYear(java.util.Date date,
FiscalCalendar fiscalCalendar)
Returns the
FiscalYear object for the fiscal year in which the passed date exists. |
static java.lang.String |
getInputFormat()
Retrieves the default format for strings being parsed into dates via
Date.parseInput() |
static LogicalDate |
getLogicalDateOnly(java.util.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(java.util.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").
|
java.lang.String |
getShortDayName(int length)
Return the abbreviated (up to 3 chars) day of week name for this date (Mon, Tue, etc).
|
java.lang.String |
getShortMonthName(int length)
Return the abbreviated (up to 3 chars) name of the month for this date (Jan, Feb, etc) To modify the value returned by
this method, use
com.smartgwt.client.util.DateUtil#setShortMonthNames() . |
java.lang.String |
getShortYear()
Return a 2 digit year for this date.
|
int |
getWeek()
Returns an integer containing the week number
|
static java.lang.Integer[] |
getWeekendDays()
Return an array of days that are considered "weekend" days.
|
static java.lang.String |
mapRelativeDateShortcut(java.lang.String relativeDateShortcut) |
static java.lang.String |
mapRelativeDateShortcut(java.lang.String relativeDateShortcut,
RelativeDateRangePosition position)
Converts a RelativeDate shortcut string such as
"$today" to a RelativeDateString such as "+0D" |
static java.util.Date |
parseInput(java.lang.String dateString)
Parse a date passed in as a string, returning the appropriate date object.
|
java.util.Date |
parseInput(java.lang.String dateString,
java.lang.String format) |
java.util.Date |
parseInput(java.lang.String dateString,
java.lang.String format,
java.lang.Integer centuryThreshold) |
static java.util.Date |
parseInput(java.lang.String dateString,
java.lang.String format,
java.lang.Integer centuryThreshold,
java.lang.Boolean suppressConversion)
Parse a date passed in as a string, returning the appropriate 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(java.lang.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(java.lang.String separator)
Sets a new default separator that will be used when formatting dates.
|
static void |
setDefaultDisplayTimezone(java.lang.String offset)
Globally sets the offset from UTC to use when formatting values of type datetime and time with
standard display formatters.
|
static void |
setFirstDayOfWeek(int firstDayOfWeek)
Sets the global attribute that dictates which day should be treated as the first day of the week in calendars and date
calculations.
|
static void |
setFiscalCalendar(FiscalCalendar fiscalCalendar)
Sets the global fiscal calendar, which is used for all calls to getFiscalYear() / getFiscalWeek() if those methods
aren't passed a fiscalCalander.
|
void |
setFormatter(java.lang.String functionName)
Deprecated.
As of Smart GWT 5.5 use the static methods
Date.setNormalDisplayFormat and Date.setShortDisplayFormat to set default formatters for all dates |
static void |
setInputFormat(java.lang.String format)
Sets up the default system-wide input format for strings being parsed into dates via
Date.parseInput() . |
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 |
setNormalDatetimeDisplayFormat(DateDisplayFormat format)
Set the default normal format for datetime values.
|
static void |
setNormalDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set the default datetime format for date objects to the DateDisplayFormat passed in.
|
static void |
setNormalDisplayFormat(DateDisplayFormat format)
Set the default formatter for date objects to the method name 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 |
setShortDisplayFormat(DateDisplayFormat format)
Set the default short format for dates.
|
static void |
setShortMonthNames(java.lang.String[] shortMonthNames)
Set the array of names of months.
|
static void |
setShortTimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short time formatting function.
|
static void |
setShowChooserFiscalYearPickers(boolean showChooserFiscalYearPickers)
|
static void |
setShowChooserWeekPickers(boolean showChooserWeekPickers)
|
static void |
setWeekendDays(java.lang.Integer[] weekendDays)
Sets the days that are considered
weekend days . |
java.lang.String |
toDateStamp()
Return this date in the format (UTC timezone):
YYYYMMDDTHHMMSS[Z] |
java.lang.String |
toEuropeanShortDate()
Return this date in the format:
DD/MM/YYYY |
java.lang.String |
toEuropeanShortDateTime()
Return this date in the format:
DD/MM/YYYY HH:MM . |
java.lang.String |
toJapanShortDate()
Return the date in this format:
YYYY/MM/DD |
java.lang.String |
toJapanShortDateTime()
Return this date in the format:
YYYY/MM/DD HH:MM:SS |
java.lang.String |
toNormalDate(DateDisplayFormat format)
Returns the date as a formatted string using the format set up via the
setNormalDisplayFormat() method. |
java.lang.String |
toNormalDatetime(DateDisplayFormat format)
Returns the datetime as a formatted string using the format set up via the
setNormalDatetimeDisplayFormat()
method. |
java.lang.String |
toNormalDatetime(DateDisplayFormat format,
java.lang.Boolean useCustomTimezone)
Returns the datetime as a formatted string using the format set up via the
setNormalDatetimeDisplayFormat()
method. |
java.lang.String |
toPrettyString()
Deprecated.
As of Smart GWT 5.5 use
Date.toShortDate instead |
java.lang.String |
toSerializeableDate()
Return this date in 'serialized' format
YYYY-MM-DD HH:MM:SS |
java.lang.String |
toShortDate(DateDisplayFormat format)
Returns the date as a formatted string using the format set up via the
setShortDisplayFormat() method. |
java.lang.String |
toShortDate(DateDisplayFormat format,
java.lang.Boolean useCustomTimezone)
Returns the date as a formatted string using the format set up via the
setShortDisplayFormat() method. |
java.lang.String |
toShortDateTime(DateDisplayFormat format)
Returns the datetime as a formatted string using the format set up via the
setShortDatetimeDisplayFormat()
method. |
java.lang.String |
toShortDateTime(DateDisplayFormat format,
java.lang.Boolean useCustomTimezone)
Returns the datetime as a formatted string using the format set up via the
setShortDatetimeDisplayFormat()
method. |
java.lang.String |
toUSShortDate()
Return this date in the format:
MM/DD/YYYY |
java.lang.String |
toUSShortDateTime()
Return this date in the format:
MM/DD/YYYY HH:MM |
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
public int getFiscalWeek()
FiscalCalendar
.public int getFiscalWeek(FiscalCalendar fiscalCalendar)
FiscalCalendar
.fiscalCalendar
- the object representing the starts of fiscal yearspublic FiscalYear getFiscalYear()
FiscalYear
object appropriate for the the current date, according to the
FiscalCalendar
.public java.lang.String getShortDayName(int length)
shortDayNames
length
- Number of characters to return (Defaults to 3, can't be longer than 3)public java.lang.String getShortMonthName(int length)
com.smartgwt.client.util.DateUtil#setShortMonthNames()
.length
- Number of characters to return (Defaults to 3, can't be longer than 3)public java.lang.String getShortYear()
public int getWeek()
public void setFormatter(java.lang.String functionName)
Date.setNormalDisplayFormat
and Date.setShortDisplayFormat
to set default formatters for all datesfunctionName
- name of a date formatter method on this Datepublic java.lang.String toDateStamp()
YYYYMMDDTHHMMSS[Z]
public java.lang.String toEuropeanShortDate()
DD/MM/YYYY
public java.lang.String toEuropeanShortDateTime()
DD/MM/YYYY HH:MM
.public java.lang.String toJapanShortDate()
YYYY/MM/DD
public java.lang.String toJapanShortDateTime()
YYYY/MM/DD HH:MM:SS
public java.lang.String toNormalDate(DateDisplayFormat format)
setNormalDisplayFormat()
method.
Note that the default formatter for this method is "toLocaleString"
.format
- Optional Format for the date returnedpublic java.lang.String toNormalDatetime(DateDisplayFormat format)
setNormalDatetimeDisplayFormat()
method.format
- Optional Format for the date returnedpublic java.lang.String toNormalDatetime(DateDisplayFormat format, java.lang.Boolean useCustomTimezone)
setNormalDatetimeDisplayFormat()
method.format
- Optional Format for the date returneduseCustomTimezone
- If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this
timezone. To suppress this behavior, this parameter should be set to false.public java.lang.String toPrettyString()
Date.toShortDate
insteadMM/DD/YY HH:MM
public java.lang.String toSerializeableDate()
YYYY-MM-DD HH:MM:SS
public java.lang.String toShortDate(DateDisplayFormat format)
setShortDisplayFormat()
method.format
- Optional Format for the date returnedpublic java.lang.String toShortDate(DateDisplayFormat format, java.lang.Boolean useCustomTimezone)
setShortDisplayFormat()
method.format
- Optional Format for the date returneduseCustomTimezone
- If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this
timezone. to suppress this behavior, this parameter should be set to false.public java.lang.String toShortDateTime(DateDisplayFormat format)
setShortDatetimeDisplayFormat()
method.format
- Optional Format for the date returnedpublic java.lang.String toShortDateTime(DateDisplayFormat format, java.lang.Boolean useCustomTimezone)
setShortDatetimeDisplayFormat()
method.format
- Optional Format for the date returneduseCustomTimezone
- If a custom timezone has been set via Time.setDefaultDisplayTimezone(), by default date formatters will respect this
timezone. to suppress this behavior, this parameter should be set to false.public java.lang.String toUSShortDate()
MM/DD/YYYY
public java.lang.String toUSShortDateTime()
MM/DD/YYYY HH:MM
public static int compareDates(java.util.Date date1, java.util.Date date2)
date1
- first date to comparedate2
- second date to comparepublic static int compareLogicalDates(java.util.Date date1, java.util.Date date2)
date1
- first date to comparedate2
- second date to comparepublic static java.util.Date create()
Date
object - synonym for new Date(arguments)
public static int getFirstDayOfWeek()
The default value is picked up from the current locale.
public static FiscalCalendar getFiscalCalendar()
FiscalCalendar object
representing the start month
and date of the fiscal year in the current locale.public static java.util.Date getFiscalStartDate(java.util.Date date)
date
- the date, or the year-number, to get the fiscal year forpublic static java.util.Date getFiscalStartDate(java.util.Date date, FiscalCalendar fiscalCalendar)
date
- the date, or the year-number, to get the fiscal year forfiscalCalendar
- the object representing the starts of one or more fiscal yearspublic static int getFiscalWeek(java.util.Date date)
date
- the date to get the fiscal year forpublic static int getFiscalWeek(java.util.Date date, FiscalCalendar fiscalCalendar)
date
- the date to get the fiscal year forfiscalCalendar
- the object representing the starts of fiscal yearspublic static FiscalYear getFiscalYear(java.util.Date date)
FiscalYear
object for the fiscal year in which the passed date exists.date
- the date to get the fiscal year forFiscalYear
object for the passed datepublic static FiscalYear getFiscalYear(java.util.Date date, FiscalCalendar fiscalCalendar)
FiscalYear
object for the fiscal year in which the passed date exists.date
- the date to get the fiscal year forfiscalCalendar
- the object representing the start of the fiscal periodFiscalYear
object for the passed datepublic static java.lang.String getInputFormat()
Date.parseInput()
com.smartgwt.client.util.Date#setInputFormat
public static java.lang.Integer[] getWeekendDays()
weekendDays
to accommodate different workweeks such as Saudi Arabia (Saturday -> Wednesday) or Israel (Sunday ->
Thursday).public static java.util.Date parseInput(java.lang.String dateString)
dateString
- date value as a stringpublic java.util.Date parseInput(java.lang.String dateString, java.lang.String format)
Date#parseInput()}
public java.util.Date parseInput(java.lang.String dateString, java.lang.String format, java.lang.Integer centuryThreshold)
Date#parseInput()}
public static java.util.Date parseInput(java.lang.String dateString, java.lang.String format, java.lang.Integer centuryThreshold, java.lang.Boolean suppressConversion)
dateString
- date value as a stringformat
- Format of the date string being passed. If not passed, the default date input
format as set up via setInputFormat() will be used.. See DateInputFormat
centuryThreshold
- For date formats that support a 2 digit year, if parsed year is 2 digits and less than
this number, assume year to be 20xx rather than 19xxsuppressConversion
- If the string passed in was not a valid date, in some cases we can convert to a valid date (for example
incrementing the year if the month is greater than 12). This optional parameter will suppress such conversions
- anything that doesn't parse directly to a valid date will simply return null.public static void setFirstDayOfWeek(int firstDayOfWeek)
The default value is picked up from the current locale.
firstDayOfWeek
- the number of the day to use as the first day of the weekpublic static void setFiscalCalendar(FiscalCalendar fiscalCalendar)
fiscalCalendar
- the object representing the start month and date of the fiscal year in the current localepublic static void setInputFormat(java.lang.String format)
Date.parseInput()
.
This will effect how Smart GWT components showing editable date or datetime fields parse user-entered values into live
Date objects. The input format can be specified as a DateInputFormat - 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:
shortDisplayFormat
wherever possible. For example if the
short display format has been set to "toEuropeanShortDate" the input format will default to "DMY".Date.toShortDate
and Date.toShortDateTime
.format
- Default format for strings to be parsed into Dates.. See DateInputFormat
com.smartgwt.client.util.Date#parseInput
public static void setNormalDatetimeDisplayFormat(DateDisplayFormat format)
Date.toNormalDatetime
will return a string formatted according to this
format specification. Note that this will be the standard datetime format used by Smart GWT components. The
format
parameter may be either a DateDisplayFormat
string, or a function.
If passed a function, this function will be executed in the scope of the Date and should return the formatted string.
format
- new formatterpublic static void setNormalDisplayFormat(DateDisplayFormat format)
Date.toNormalDate
will return a string formatted according to this
format specification. Note: this will be the standard long date format used by Smart GWT components.format
parameter may be either a DateDisplayFormat
string, or a function.
If passed a function, this function will be executed in the scope of the Date and should return the formatted
string."toLocaleString"
format
- new formatterpublic static void setShortDisplayFormat(DateDisplayFormat format)
Date.toShortDate
will return a string formatted according to this format
specification. Note that this will be the standard short date format used by Smart GWT components. The
format
parameter may be either a DateDisplayFormat
string, or a function.
If passed a function, this function will be executed in the scope of the Date and should return the formatted string.
Initial default shortDateFormat is "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
- new formatterpublic static void setShowChooserFiscalYearPickers(boolean showChooserFiscalYearPickers)
choosers
shelled
from DateItems
show a UI for working with Fiscal Years.showChooserFiscalYearPickers
- whether to show Fiscal Year pickers in DateChoosers by defaultpublic static void setShowChooserWeekPickers(boolean showChooserWeekPickers)
choosers
shelled
from DateItems
show a UI for working with Weeks.showChooserWeekPickers
- whether to show Fiscal Week pickers in DateChoosers by defaultpublic static void setWeekendDays(java.lang.Integer[] weekendDays)
weekend days
. The parameter should
be array of the integers returned by the JavaScript built-in Date.getDay(), eg, 0 is Sunday and 6 is Saturday.
Override to accommodate different workweeks such as Saudi Arabia (Saturday -> Wednesday) or Israel (Sunday ->
Thursday).weekendDays
- the array of day-numbers to assign as weekend dayspublic static void setDefaultDisplayTimezone(java.lang.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(java.lang.String separator)
separator
- the date separatorpublic static java.lang.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 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 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 DateDisplayFormatterpublic 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 LogicalDate getLogicalDateOnly(java.util.Date date)
This method correctly takes into account the current String, specifically, the returned Date will reflect the day, month and year that appears when the datetime is rendered by a Smart GWT 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
this overview
.
date
- a Date instance representing a datetime valuepublic static LogicalTime getLogicalTimeOnly(java.util.Date date)
This method correctly takes into account the current String, specifically, the returned Date will reflect the hour, minute and second that appears when the datetime is rendered by a Smart GWT 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 this overview
.
date
- a Date instance representing a datetime valuepublic static java.lang.String formatAsShortDate(java.util.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 java.lang.String formatAsShortDatetime(java.util.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 java.lang.String format(java.util.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 java.lang.String formatAsNormalDate(java.util.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 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(java.lang.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:
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 java.lang.String mapRelativeDateShortcut(java.lang.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 java.lang.String mapRelativeDateShortcut(java.lang.String relativeDateShortcut)
public static java.util.Date getAbsoluteDate(RelativeDate relativeDate)
public static java.util.Date getAbsoluteDate(RelativeDate relativeDate, java.util.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 java.util.Date combineLogicalDateAndTime(java.util.Date date, java.util.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
this overview
.
date
- time
- public static void setShortMonthNames(java.lang.String[] shortMonthNames)
new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }The appropriate month name will then be returned from
#getShortMonthName()
, and
may be used whenever SmartGWT components display month-names (for example in the
DateItem class
).
Note : This is an advanced setting
shortMonthNames
- a length 12 array of abbreviated month namespublic static java.util.Date getFiscalStartDate(java.lang.Integer year, FiscalCalendar fiscalCalendar)
public static void autoDetectFormats()