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 void |
clearDateParser()
If a custom system wide date parser has been specified via
setDateParser(DateParser) , clear this and
revert to the standard date input format specified via setDateInputFormat(String) . |
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
setNormalDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
format(java.util.Date date,
java.lang.String format)
Format the parameter date using the parameter format string.
|
static java.lang.String |
formatAsNormalDate(java.util.Date date)
Format a date as a string according to the format specified by
setNormalDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
formatAsShortDate(java.util.Date date)
Format a date as a string according to the format specified by
setShortDateDisplayFormatter(DateDisplayFormatter) . |
static java.lang.String |
formatAsShortDatetime(java.util.Date date)
Format a date as a string according to the format specified by
setShortDatetimeDisplayFormatter(DateDisplayFormatter) . |
static java.util.Date |
getAbsoluteDate(RelativeDate relativeDate)
|
static java.util.Date |
getAbsoluteDate(RelativeDate relativeDate,
java.util.Date baseDate)
|
static java.util.Date |
getAbsoluteDate(java.lang.String relativeDateShortcut,
java.util.Date baseDate,
RelativeDateRangePosition rangePosition) |
static java.lang.String |
getDayName(java.util.Date date)
Return the full day of week name for this date (Monday, Tuesday, etc).
|
static java.lang.String |
getDefaultDateSeparator()
gets the default date separator string
|
static int |
getDisplayDay(java.util.Date datetime)
Returns the day of month from the passed datetime, as it will be displayed to the user.
|
static int |
getDisplayHours(java.util.Date datetime)
Returns the hours value from the passed datetime, as it will be displayed to the user.
|
static int |
getDisplayMinutes(java.util.Date datetime)
Returns the minutes value from the passed datetime, as it will be displayed to the user.
|
static int |
getDisplayMonth(java.util.Date datetime)
Returns the month number from the passed datetime, as it will be displayed to the user.
|
static int |
getDisplayYear(java.util.Date datetime)
Returns the full year from the passed datetime, as it will be displayed to the user.
|
static java.util.Date |
getEndOf(java.util.Date date,
java.lang.String period)
Returns the end of some period, like day, week or month, relative to a passed Date instance.
|
static java.util.Date |
getEndOf(java.util.Date date,
java.lang.String period,
java.lang.Boolean logicalDate) |
static java.util.Date |
getEndOf(java.util.Date date,
java.lang.String period,
java.lang.Boolean logicalDate,
java.lang.Integer firstDayOfWeek)
Returns the end of some period, like day, week or month, relative to a passed Date instance.
|
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.
|
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
|
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
DateUtil.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 |
getMonthName(java.util.Date date)
Return the full name of the month for this date (January, February, etc) To modify the
value returned by this method, use
com.smartgwt.client.util.DateUtil#setMonthNames() . |
java.lang.String |
getShortDayName(java.util.Date date)
Return the abbreviated (up to 3 chars) day of week name for this date (Mon, Tue, etc).
|
java.lang.String |
getShortMonthName(java.util.Date date)
Return the abbreviated 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(java.util.Date date)
Return a 2 digit year for this date.
|
static java.util.Date |
getStartOf(java.util.Date date,
java.lang.String period)
Returns the start of some period, like day, week or month, relative to a passed Date instance.
|
static java.util.Date |
getStartOf(java.util.Date date,
java.lang.String period,
java.lang.Boolean logicalDate) |
static java.util.Date |
getStartOf(java.util.Date date,
java.lang.String period,
java.lang.Boolean logicalDate,
java.lang.Integer firstDayOfWeek)
Returns the start of some period, like day, week or month, relative to a passed Date instance.
|
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.
|
static java.util.Date |
parseInput(java.lang.String dateString,
java.lang.String format) |
static 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 |
setDayNames(java.lang.String[] dayNames)
Set the array of names of days.
|
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.
|
static void |
setInputFormat(java.lang.String format)
Sets up the default system-wide input format for strings being parsed into dates via
DateUtil.parseInput() . |
static void |
setMonthNames(java.lang.String[] monthNames)
Set the array of names of months.
|
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 |
setShortDateDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short date formatting function.
|
static void |
setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
Set up a system wide default short datetime formatting function.
|
static void |
setShortDayNames(java.lang.String[] shortDayNames)
Set the array of shortened names of days.
|
static void |
setShortDisplayFormat(java.lang.String 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(java.util.Date date)
Return this date in the format (UTC timezone):
YYYYMMDDTHHMMSS[Z] |
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 static java.util.Date combineLogicalDateAndTime(java.util.Date date, java.util.Date time)
This method correctly takes into account the current String, specifically, the returned datetime value will show the same date and time as the passed date and time objects when rendered by a Smart GWT component that has been configured with a field of type "datetime".
For further background on date, time and datetime types,
storage and transmission, see this overview
.
date
- a Date instance representing logical date valuetime
- a Date instance representing logical time valuepublic 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 java.util.Date getAbsoluteDate(RelativeDate relativeDate)
relativeDate
- the relative date to convertpublic static java.util.Date getAbsoluteDate(RelativeDate relativeDate, java.util.Date baseDate)
relativeDate
- the relative date to convertbaseDate
- base value for conversion. Defaults to the current date/time.public static java.lang.String getDefaultDateSeparator()
public static int getDisplayDay(java.util.Date datetime)
datetime
- datetime instance to work withpublic static int getDisplayHours(java.util.Date datetime)
datetime
- datetime instance to work withpublic static int getDisplayMinutes(java.util.Date datetime)
datetime
- datetime instance to work withpublic static int getDisplayMonth(java.util.Date datetime)
datetime
- datetime instance to work withpublic static int getDisplayYear(java.util.Date datetime)
datetime
- datetime instance to work withpublic static java.util.Date getEndOf(java.util.Date date, java.lang.String period)
date
- the base date to find the period end fromperiod
- the period to return the end of, one of mn/h/d/w/m/ypublic static java.util.Date getEndOf(java.util.Date date, java.lang.String period, java.lang.Boolean logicalDate)
public static java.util.Date getEndOf(java.util.Date date, java.lang.String period, java.lang.Boolean logicalDate, java.lang.Integer firstDayOfWeek)
date
- the base date to find the period end fromperiod
- the period to return the end of, one of mn/h/d/w/m/ylogicalDate
- process and return a logicalDate with no time elementfirstDayOfWeek
- which day should be considered the firstDayOfWeek - overrides the default provided by the localepublic 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()
DateUtil.parseInput()
setInputFormat(java.lang.String)
public static java.util.Date getStartOf(java.util.Date date, java.lang.String period)
date
- the base date to find the period start fromperiod
- the period to return the start of, one of mn/h/d/w/m/ypublic static java.util.Date getStartOf(java.util.Date date, java.lang.String period, java.lang.Boolean logicalDate)
public static java.util.Date getStartOf(java.util.Date date, java.lang.String period, java.lang.Boolean logicalDate, java.lang.Integer firstDayOfWeek)
date
- the base date to find the period start fromperiod
- the period to return the start of, one of mn/h/d/w/m/ylogicalDate
- process and return a logicalDate with no time elementfirstDayOfWeek
- which day should be considered the firstDayOfWeek - overrides the default provided by the localepublic 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 static java.util.Date parseInput(java.lang.String dateString, java.lang.String format)
parseInput(java.lang.String)
public static java.util.Date parseInput(java.lang.String dateString, java.lang.String format, java.lang.Integer centuryThreshold)
parseInput(java.lang.String)
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 setDefaultDateSeparator(java.lang.String separator)
separator
- separator to use in datespublic 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)
DateUtil.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:
DateUtil.shortDisplayFormat
wherever
possible. For example if the short display format has been set to "toEuropeanShortDate" the input format will
default to "DMY".formatAsShortDate()
and formatAsShorDatetime()
. format
- Default format for strings to be parsed into Dates.
See DateInputFormat
parseInput(java.lang.String)
public static void setShortDisplayFormat(java.lang.String format)
formatAsShortDate
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 a FormatString
, 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 formatter.
See FormatString
public 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 java.lang.String getDayName(java.util.Date date)
setDayNames(java.lang.String[])
.date
- public java.lang.String getShortDayName(java.util.Date date)
setShortDayNames(java.lang.String[])
.date
- public java.lang.String getMonthName(java.util.Date date)
com.smartgwt.client.util.DateUtil#setMonthNames()
.date
- public java.lang.String getShortMonthName(java.util.Date date)
com.smartgwt.client.util.DateUtil#setShortMonthNames()
.date
- public java.lang.String getShortYear(java.util.Date date)
date
- public java.lang.String toDateStamp(java.util.Date date)
YYYYMMDDTHHMMSS[Z]
date
- public 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 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; } });As of version 4.1, SmartGWT has built-in string-based formatting of date and time values via the
DateFormatStringFormatter
class. The main advantage of using the built-in
formatting feature is that it is harmonized with the formatting we export to Excel and other
targets, leading to an exported document that more closely resembles the original application.
See com.smartgwt.client.data.DataSOurceField#format
for details.
Sample code :
DateUtil.setNormalDateDisplayFormatter(new DateFormatStringFormatter("yyyy.MM.dd HH:mm:ss"));
formatter
- the DateDisplayFormatterpublic 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 DateDisplayFormatterpublic 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)
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)
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)
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)
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)
setShortDateDisplayFormatter(DateDisplayFormatter)
and
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:
inputFormat
- public static void clearDateParser()
setDateParser(DateParser)
, clear this and
revert to the standard date input format specified via setDateInputFormat(String)
.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(java.lang.String relativeDateShortcut, java.util.Date baseDate, RelativeDateRangePosition rangePosition)
relativeDateShortcut
- the
RelativeDateShortcut
or RelativeDateString
string to convertbaseDate
- base value for conversion. Defaults to the current date/time.rangePosition
- date-range position. Only has an effect if the date passed in is a
RelativeDateShortcut
where the
range position is not implicit, such as "$yesterday"getAbsoluteDate(com.smartgwt.client.data.RelativeDate)
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.
As of version 4.1, SmartGWT has built-in string-based formatting of date and time values via
the DateFormatStringFormatter
class. The main advantage of using the built-in
formatting feature is that it is harmonized with the formatting we export to Excel and other
targets, leading to an exported document that more closely resembles the original application.
See com.smartgwt.client.data.DataSourceField#format
for details.
Sample code :
DateUtil.setNormalTimeDisplayFormatter(new DateFormatStringFormatter("HH-mm-ss"));
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.lang.String format(java.util.Date date, java.lang.String format)
DateFormatStringFormatter
and calls its format()
methoddate
- the Date to formatformat
- the format string to usepublic static void setDayNames(java.lang.String[] dayNames)
new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }The appropriate day name will then be returned from
#getDayName()
, and may be
used whenever SmartGWT components display day-names (for example in the
DateItem class
).
Note : This is an advanced setting
dayNames
- a length 7 array of day namespublic static void setShortDayNames(java.lang.String[] shortDayNames)
new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }The appropriate day name will then be returned from
#getShortDayName()
, and
may be used whenever SmartGWT components display shortened day-names (for example in the
DateItem class
).
Note : This is an advanced setting
shortDayNames
- a length 7 array of abbreviated day namespublic static void setMonthNames(java.lang.String[] monthNames)
new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }The appropriate month name will then be returned from
#getMonthName()
, and may
be used whenever SmartGWT components display month-names (for example in the
DateItem class
).
Note : This is an advanced setting
monthNames
- a length 12 array of month namespublic 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()