Class sap.ui.core.format.DateFormatModule: sap/ui/core/format/DateFormat


The DateFormat is a static class for formatting and parsing date and time values according to a set of format options.

Supported format options are pattern based on Unicode LDML Date Format notation. If no pattern is specified a default pattern according to the locale settings is used.

Constructor Summary
new sap.ui.core.format.DateFormat()Constructor for DateFormat - must not be used: To get a DateFormat instance, please use getInstance, getDateTimeInstance or getTimeInstance.
Method Summary
sap.ui.core.format.DateFormat.getDateInstance(oFormatOptions?, oLocale?)Get a date instance of the DateFormat, which can be used for formatting.
sap.ui.core.format.DateFormat.getDateTimeInstance(oFormatOptions?, oLocale?)Get a datetime instance of the DateFormat, which can be used for formatting.
sap.ui.core.format.DateFormat.getTimeInstance(oFormatOptions?, oLocale?)Get a time instance of the DateFormat, which can be used for formatting.
format(oDate, bUTC)Format a date according to the given format options.
parse(sValue, bUTC, bStrict)Parse a string which is formatted according to the given format options.
Constructor Detail
new sap.ui.core.format.DateFormat()
Constructor for DateFormat - must not be used: To get a DateFormat instance, please use getInstance, getDateTimeInstance or getTimeInstance.
See:
http://unicode.org/reports/tr35/#Date_Field_Symbol_Table
Method Detail
sap.ui.core.format.DateFormat.getDateInstance(oFormatOptions?, oLocale?): sap.ui.core.format.DateFormat
Get a date instance of the DateFormat, which can be used for formatting.
Parameters:
{object}oFormatOptions? Object which defines the format options
{string}oFormatOptions.pattern? a data pattern in LDML format. It is not verified whether the pattern represents only a date.
{string}oFormatOptions.style? can be either 'short, 'medium', 'long' or 'full'. If no pattern is given, a locale dependent default date pattern of that style is used from the LocaleData class.
{boolean}oFormatOptions.strictParsing? if true, by parsing it is checked if the value is a valid date
{boolean}oFormatOptions.relative? if true, the date is formatted relatively to todays date if it is within the given day range, e.g. "today", "yesterday", "in 5 days"
{int[]}oFormatOptions.relativeRange? the day range used for relative formatting. If oFormatOptions.relatvieScale is set to default value 'day', the relativeRange is by default [-6, 6], which means only the last 6 days, today and the next 6 days are formatted relatively. Otherwise when oFormatOptions.relativeScale is set to 'auto', all dates are formatted relatively.
{string}oFormatOptions.relativeScale?, Default: "day" if 'auto' is set, new relative time format is switched on for all Date/Time Instances. The relative scale is chosen depending on the difference between the given date and now.
{string}oFormatOptions.relativeStyle?, Default: "wide" @since 1.32.10, 1.34.4 the style of the relative format. The valid values are "wide", "short", "narrow"
{boolean}oFormatOptions.UTC? if true, the date is formatted and parsed as UTC instead of the local timezone
{sap.ui.core.CalendarType}oFormatOptions.calendarType? The calender type which is used to format and parse the date. This value is by default either set in configuration or calculated based on current locale.
{sap.ui.core.Locale}oLocale? Locale to ask for locale specific texts/settings
Returns:
{sap.ui.core.format.DateFormat} date instance of the DateFormat
sap.ui.core.format.DateFormat.getDateTimeInstance(oFormatOptions?, oLocale?): sap.ui.core.format.DateFormat
Get a datetime instance of the DateFormat, which can be used for formatting.
Parameters:
{object}oFormatOptions? Object which defines the format options
{string}oFormatOptions.pattern? a datetime pattern in LDML format. It is not verified whether the pattern represents a full datetime.
{string}oFormatOptions.style? can be either 'short, 'medium', 'long' or 'full'. For datetime you can also define mixed styles, separated with a slash, where the first part is the date style and the second part is the time style (e.g. "medium/short"). If no pattern is given, a locale dependent default datetime pattern of that style is used from the LocaleData class.
{boolean}oFormatOptions.strictParsing? if true, by parsing it is checked if the value is a valid datetime
{boolean}oFormatOptions.relative? if true, the date is formatted relatively to todays date if it is within the given day range, e.g. "today", "yesterday", "in 5 days"@param {boolean} [oFormatOptions.UTC] if true, the date is formatted and parsed as UTC instead of the local timezone
{int[]}oFormatOptions.relativeRange? the day range used for relative formatting. If oFormatOptions.relatvieScale is set to default value 'day', the relativeRange is by default [-6, 6], which means only the last 6 days, today and the next 6 days are formatted relatively. Otherwise when oFormatOptions.relativeScale is set to 'auto', all dates are formatted relatively.
{string}oFormatOptions.relativeScale?, Default: "day" if 'auto' is set, new relative time format is switched on for all Date/Time Instances. The relative scale is chosen depending on the difference between the given date and now.
{string}oFormatOptions.relativeStyle?, Default: "wide" @since 1.32.10, 1.34.4 the style of the relative format. The valid values are "wide", "short", "narrow"
{boolean}oFormatOptions.UTC? if true, the date is formatted and parsed as UTC instead of the local timezone
{sap.ui.core.CalendarType}oFormatOptions.calendarType? The calender type which is used to format and parse the date. This value is by default either set in configuration or calculated based on current locale.
{sap.ui.core.Locale}oLocale? Locale to ask for locale specific texts/settings
Returns:
{sap.ui.core.format.DateFormat} datetime instance of the DateFormat
sap.ui.core.format.DateFormat.getTimeInstance(oFormatOptions?, oLocale?): sap.ui.core.format.DateFormat
Get a time instance of the DateFormat, which can be used for formatting.
Parameters:
{object}oFormatOptions? Object which defines the format options
{string}oFormatOptions.pattern? a time pattern in LDML format. It is not verified whether the pattern only represents a time.
{string}oFormatOptions.style? can be either 'short, 'medium', 'long' or 'full'. If no pattern is given, a locale dependent default time pattern of that style is used from the LocaleData class.
{boolean}oFormatOptions.strictParsing? if true, by parsing it is checked if the value is a valid time
{boolean}oFormatOptions.relative? if true, the date is formatted relatively to todays date if it is within the given day range, e.g. "today", "yesterday", "in 5 days"
{int[]}oFormatOptions.relativeRange? the day range used for relative formatting. If oFormatOptions.relatvieScale is set to default value 'day', the relativeRange is by default [-6, 6], which means only the last 6 days, today and the next 6 days are formatted relatively. Otherwise when oFormatOptions.relativeScale is set to 'auto', all dates are formatted relatively.
{string}oFormatOptions.relativeScale?, Default: "day" if 'auto' is set, new relative time format is switched on for all Date/Time Instances. The relative scale is chosen depending on the difference between the given date and now.
{string}oFormatOptions.relativeStyle?, Default: "wide" @since 1.32.10, 1.34.4 the style of the relative format. The valid values are "wide", "short", "narrow"
{boolean}oFormatOptions.UTC? if true, the time is formatted and parsed as UTC instead of the local timezone
{sap.ui.core.CalendarType}oFormatOptions.calendarType? The calender type which is used to format and parse the date. This value is by default either set in configuration or calculated based on current locale.
{sap.ui.core.Locale}oLocale? Locale to ask for locale specific texts/settings
Returns:
{sap.ui.core.format.DateFormat} time instance of the DateFormat
format(oDate, bUTC): string
Format a date according to the given format options.
Parameters:
{Date}oDate the value to format
{boolean}bUTC whether to use UTC
Returns:
{string} the formatted output value. If an invalid date is given, an empty string is returned.
parse(sValue, bUTC, bStrict): Date
Parse a string which is formatted according to the given format options.
Parameters:
{string}sValue the string containing a formatted date/time value
{boolean}bUTC whether to use UTC, if no timezone is contained
{boolean}bStrict to use strict value check
Returns:
{Date} the parsed value