public final class DateUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.util.Date |
clone(java.util.Date date)
Clone of date safely without the need for null-checks.
|
static java.text.DateFormat |
createDisplayFormatInstance(java.util.Locale locale,
java.lang.String format,
java.lang.Boolean displayTime)
Returns a
DateFormat instance that can be used to format dates
for display in the user interface. |
static java.lang.String |
format(java.util.Date date)
Format a java.util.Date instance to a format that is accepted by Matrix
when editing a datetime property.
|
static java.lang.String |
format(java.text.DateFormat format,
java.util.TimeZone tz,
java.util.Date date)
Formats a particular date with a
date format. |
static java.lang.String |
format(java.text.DateFormat format,
java.util.TimeZone tz,
long date) |
static java.lang.String |
format(java.util.Date date,
java.util.TimeZone tz,
java.util.Locale locale) |
static java.lang.String |
formatForDisplay(java.util.Date date,
java.util.Locale locale)
Format a java.util.Date instance to a display-friendly format for the
specified locale.
|
static java.lang.String |
formatForDisplay(java.lang.String date,
java.util.Locale locale)
Format a date value retrieved from Matrix into the display format for the
specified locale.
|
static java.lang.String |
formatISO8601Date(java.util.Date date)
Formats the date according to yyyy-MM-dd.
|
static java.lang.String |
formatISO8601Date(java.util.Date date,
java.util.TimeZone tz)
Returns the ISO-8601 formatted date string using the specified time zone
|
static java.lang.String |
formatISO8601Date(long date)
Formats the date according to yyyy-MM-dd.
|
static java.lang.String |
formatISO8601Date(long date,
java.util.TimeZone tz)
Returns the ISO-8601 formatted date string using the specified time zone
|
static java.lang.String |
formatISO8601DateTime(java.util.Date date)
Formats the date according to yyyy-MM-dd'T'HH:mm:ss.
|
static java.lang.String |
formatISO8601DateTime(java.util.Date date,
java.util.TimeZone tz)
Returns the ISO-8601 formatted date+time string using the specified time
zone.
|
static java.lang.String |
formatISO8601DateTime(long date)
Formats the date according to yyyy-MM-dd'T'HH:mm:ss.
|
static java.lang.String |
formatISO8601DateTime(long date,
java.util.TimeZone tz)
Returns the ISO-8601 formatted date+time string using the specified time
zone.
|
static java.lang.String |
formatISO8601Time(java.util.Date date)
Formats the date according to HH:mm:ss.
|
static java.lang.String |
formatISO8601Time(long date)
Formats the date according to HH:mm:ss.
|
static java.text.DateFormat |
getDateDisplayFormatInstance(java.util.Locale locale)
Returns a date format instance that can be used to format dates for
display in the user interface.
|
static java.text.DateFormat |
getDateFormatInstance()
Returns a java.text.DateFormat instance that can be used to parse
datetime values retrieved from Matrix to java.util.Date instances.
|
static java.text.DateFormat |
getDateTimeDisplayFormatInstance(java.util.Locale locale)
Returns a date format instance that can be used to format dates for
display in the user interface.
|
static java.text.DateFormat |
getDisplayFormatInstance()
Returns a
DateFormat instance that can be used to format dates
for display in the user interface. |
static java.text.DateFormat |
getDisplayFormatInstance(java.util.Locale locale)
Returns the default
DateFormat instance that can be used to
format dates for display in the user interface. |
static java.lang.String |
getDurationString(java.util.Locale locale,
long time) |
static java.lang.String |
getDurationString(java.util.Locale locale,
long start,
long end)
Returns the duration between two times in a more user friendly format
|
static java.util.Calendar |
getGregorianCalendar()
Returns a Gregorian Calendar instance.
|
static java.text.DateFormat |
getInputDateFormatInstance()
Returns a java.text.DateFormat instance that can be used to convert
java.util.Date instances to a format accepted by Matrix when editing a
datetime property.
|
static java.util.TimeZone |
getUserTimeZone()
Reads the preference "preference_TimeZone" on the Person admin object,
and returns a corresponding
TimeZone instance. |
static java.util.Date |
parse(java.lang.String dateTimeValue)
Parse a datetime value retrieved from Matrix to a java.util.Date
instance.
|
static java.util.Date |
parse(java.lang.String dateTimeValue,
boolean noErrorLog)
Parse a datetime value retrieved from Matrix to a java.util.Date
based on boolean.
|
static java.util.Date |
parse(java.lang.String dateTimeValue,
java.util.TimeZone tz)
Parse a date time value retrieved from Matrix to a java.util.Date based
on time zone
|
static java.util.Date |
parseISO8601Date(java.lang.String s)
Parse a date from the string.
|
static java.util.Date |
parseISO8601Date(java.lang.String s,
java.util.TimeZone tz)
Parse a date from the string based on timezone.
|
static java.util.Date |
parseISO8601DateTime(java.lang.String s)
Parse a date from the string.
|
static java.util.Date |
parseISO8601DateTime(java.lang.String s,
java.util.TimeZone tz)
Parse a date from the string based on time zone.
|
static long |
toMilliSeconds(java.lang.String s)
Parses a string containing a time definition into milliseconds.
|
static long |
toMilliSeconds(java.lang.String s,
boolean timeUnits)
See
toMilliSeconds(String) for details. |
static java.util.TimeZone |
utc()
Returns the UTC time zone instance.
|
public static java.util.Date clone(java.util.Date date)
date - The date to clone.public static java.util.TimeZone utc()
time zonepublic static java.lang.String formatISO8601Date(java.util.Date date,
java.util.TimeZone tz)
date - The date to formattz - The time zone instanceformat(DateFormat, TimeZone, Date)public static java.lang.String formatISO8601Date(long date,
java.util.TimeZone tz)
date - The date to formattz - The time zone instanceformat(DateFormat, TimeZone, long)public static java.lang.String formatISO8601DateTime(java.util.Date date,
java.util.TimeZone tz)
date - The date to formattz - The time zone instanceformat(DateFormat, TimeZone, Date)public static java.lang.String formatISO8601DateTime(long date,
java.util.TimeZone tz)
date - The date to formattz - The time zone instanceformat(DateFormat, TimeZone, long)public static java.lang.String format(java.text.DateFormat format,
java.util.TimeZone tz,
long date)
format - The date format instancetz - The time zone instancedate - The date to formatformat(DateFormat, TimeZone, Date)public static java.lang.String format(java.text.DateFormat format,
java.util.TimeZone tz,
java.util.Date date)
date format.
The time is converted to the provided time zone. If the
tz argument is null, the default time zone is used (
TimeZone.getDefault()).
format - The DateFormattz - The time zone instancedate - The date to formatpublic static java.lang.String format(java.util.Date date,
java.util.TimeZone tz,
java.util.Locale locale)
date - The date to formattz - The time zone instancelocale - The locale instancepublic static java.util.TimeZone getUserTimeZone()
throws TVCException
TimeZone instance.TVCExceptionpublic static java.lang.String getDurationString(java.util.Locale locale,
long time)
public static java.lang.String getDurationString(java.util.Locale locale,
long start,
long end)
locale - The locale (null implies English locale)start - The start timeend - The end time (if less than 0; the current time will be used)public static java.util.Date parse(java.lang.String dateTimeValue)
public static java.util.Date parse(java.lang.String dateTimeValue,
boolean noErrorLog)
public static java.util.Date parse(java.lang.String dateTimeValue,
java.util.TimeZone tz)
dateTimeValue - A string representing the date.tz - Time zonepublic static java.lang.String format(java.util.Date date)
public static java.lang.String formatForDisplay(java.util.Date date,
java.util.Locale locale)
public static java.lang.String formatForDisplay(java.lang.String date,
java.util.Locale locale)
public static java.text.DateFormat getDateFormatInstance()
public static java.text.DateFormat getInputDateFormatInstance()
public static java.util.Calendar getGregorianCalendar()
public static java.text.DateFormat getDisplayFormatInstance()
DateFormat instance that can be used to format dates
for display in the user interface. The returned DateFormat will use the
default locale for TVC, use getDisplayFormatInstance(Locale) to
get an instance that is localized for a specified user.public static java.text.DateFormat getDisplayFormatInstance(java.util.Locale locale)
DateFormat instance that can be used to
format dates for display in the user interface.
Note that the created DateFormat instance will be configured according to settings made inside the emxSystem.properties file. E.g.
locale - The current locale. Null value forces the server default
locale to be used.DateFormat instancepublic static java.text.DateFormat getDateDisplayFormatInstance(java.util.Locale locale)
locale - The current locale. Null value forces the server default
locale to be used.DateFormat instancepublic static java.text.DateFormat getDateTimeDisplayFormatInstance(java.util.Locale locale)
locale - The current locale. Null value forces the server default
locale to be used.DateFormat instancepublic static java.text.DateFormat createDisplayFormatInstance(java.util.Locale locale,
java.lang.String format,
java.lang.Boolean displayTime)
DateFormat instance that can be used to format dates
for display in the user interface. In addition to the
getDisplayFormatInstance(Locale) method, this method allows you
to override the default values for format and displayTime. Therefore,
this method will always create a new instance that will be returned.locale - The locale of the displayed date. If null, the system wide
default value will be used.format - The format. Should equal to either SHORT, MEDIUM, LONG or
FULL. If null, the system wide default value will be used.displayTime - Whether to display time. If null, the system wide
default value will be used.DateFormat instance.public static java.lang.String formatISO8601Date(java.util.Date date)
date - The date to format.public static java.lang.String formatISO8601Date(long date)
date - The date to format expressed in milliseconds.public static java.lang.String formatISO8601Time(long date)
date - The date to format expressed in milliseconds.public static java.lang.String formatISO8601Time(java.util.Date date)
date - The date to format.public static java.util.Date parseISO8601Date(java.lang.String s)
throws java.text.ParseException
s - A string representing the date.java.text.ParseException - If unable to parse the specified string.public static java.util.Date parseISO8601Date(java.lang.String s,
java.util.TimeZone tz)
throws java.text.ParseException
s - A string representing the date.tz - Time zonejava.text.ParseException - If unable to parse the specified string.public static java.lang.String formatISO8601DateTime(java.util.Date date)
date - The date to format.public static java.lang.String formatISO8601DateTime(long date)
date - The date to format expressed in milliseconds.public static java.util.Date parseISO8601DateTime(java.lang.String s)
throws java.text.ParseException
s - A string representing the date.java.text.ParseException - If unable to parse the specified string.public static java.util.Date parseISO8601DateTime(java.lang.String s,
java.util.TimeZone tz)
s - A string representing the date.tz - Time zonejava.text.ParseException - If unable to parse the specified string.public static long toMilliSeconds(java.lang.String s)
Below is a table showing some examples of different arguments and how it will be interpreted:
| Specification | Parsed Into |
|---|---|
| 10s | 10000 ms |
| 1m | 60000 ms |
| 1m 10s | 70000 ms |
| 1h 55m 10s | 6910000 ms |
The string must follow this specification:
spec :== <part>(<sep><part>)* part :== [0-9]*[WwHhMmSs] sep :== anything (space, comma, character etc.)Some notes:
w or W is representing a week (7 days)
d or D is representing one day (24 hours)
m or M is representing one minute (60 seconds)
s - The string to parsepublic static long toMilliSeconds(java.lang.String s,
boolean timeUnits)
toMilliSeconds(String) for details.
The difference is that if the argument timeUnits is set to false, then the hour, minute and second fields are ignored. The 'm' or 'M' character is treated as month.
s - The string to parsetimeUnits - True if to treat 'm' or 'M' as minute and 's' or 'S' as
seconds. If false, 's' or 'S' is ignored and 'm' or 'M' are
treated as months.Copyright ? Technia AB. All Rights Reserved.