Top
You are looking at an outdated 7.13.1 version of this document. Switch to the 7.14.3 version to see the up to date information.

namespace anychart.format Improve this Doc

Namespace for format.

Functions Overview

date()Formats date by pattern.
dateTime()Formats date time by pattern.
getDateTimeFormat()Gets datatime format from locale by identifier and index.
getDateTimeFormats()Gets all datatime formats from locale by identifier.
getIntervalIdentifier()Get interval identifier by unit name.
getMessage()Returns localized message if the translation is provided in messages section of output locale.
inputBaseDate()Input base date settings.
inputDateTimeFormat()Input date time format
inputLocale()Input format settings to be used.
number()Formats number.
outputDateFormat()Getter only current output date format.
outputDateTimeFormat()Getter for the output date and time format.
outputLocale()Output format settings to be used.
outputTimeFormat()Getter only current output time format.
outputTimezone()Output timezone settings.
parseDateTime()Parses input value to date.
parseNumber()Parses value to number according to locale set.
subs()Formats for string substitution.
time()Formats time by pattern.

Typedefs Overview

anychart.format.DateTimeLocaleType definition for date time localization.
anychart.format.LocaleType definition for localization.
anychart.format.NumberLocaleType definition for number locale.
anychart.format.localesContains a list of the used localizations.

Classes Overview

anychart.format.ContextCommon format context class.

Functions Description

date

Formats date by pattern.
The same that anychart.format.dateTime but with the anychart.format#outputDateFormat as default datetime format.

Params:

Name Type Description
date number | Date UTC timestamp or Date object.
timeZone number Adjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
locale string | anychart.format.Locale Locale to be used.

Returns:

string - Formatted value.

Try it:

dateTime

Formats date time by pattern.

Params:

Name Type Description
date number | Date UTC timestamp or Date object.
format string Format of date ['yyyy.MM.dd'].
timeZone number Adjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
locale string | anychart.format.Locale Locale to be used.

Returns:

string - Formatted value.

Try it:

getDateTimeFormat

Gets datatime format from locale by identifier and index. To get all formats use anychart.format#getDateTimeFormats.

Params:

Name Type Default Description
identifier string
Use anychart.format#getIntervalIdentifier to get correct identifier
index number
0
If locale has more than one format.
locale anychart.format.Locale
Locale to be used.

Returns:

string -
anychart.format.getDateTimeFormat
// for example in 'de-de' locale defined
// 'year_day': ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']
var identifier = anychart.format.getIntervalIdentifier('days','years');
var format = anychart.format.getDateTimeFormat(identifier, 2, 'de-de');
// format = 'yyyy MMMM dd'

getDateTimeFormats

Gets all datatime formats from locale by identifier. To get one format by index use anychart.format#getDateTimeFormat.

Params:

Name Type Description
identifier string Use anychart.format#getIntervalIdentifier to get correct identifier
locale anychart.format.Locale Locale to be used.

Returns:

string -
anychart.format.getDateTimeFormat
// for example in 'de-de' locale defined
// 'year_day': ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']
var identifier = anychart.format.getIntervalIdentifier('days','years');
var allFormats = anychart.format.getDateTimeFormat(identifier, 'de-de');
// allFormats = ['EEEE, y MMMM dd', 'yy MM dd', 'yyyy MMMM dd']

getIntervalIdentifier

Get interval identifier by unit name.

Params:

Name Type Description
intervalUnit anychart.enums.Interval Name of unit interval.
parentIntervalUnit anychart.enums.Interval Name of parent unit interval.

Returns:

string - Correct interval identifier by unit name.
Use anychart.format.getIntervalIdentifier
anychart.format.getIntervalIdentifier('day','year');
anychart.format.getIntervalIdentifier('d','y');
// returns 'year_day'

getMessage

Returns localized message if the translation is provided in messages section of output locale.

Params:

Name Type Description
keyword anychart.enums.Interval Keyword.

Returns:

string - Message from current locale by keyword or a keyword itself if a message doesn't exist.

Try it:

inputBaseDate

Getter for the input base date.

Returns:

Date - The input base date. Date -
Setter for the input base date.

Params:

Name Type Description
value Date | number

Returns:

Date - The input base date.
Example
anychart.format.inputBaseDate(Date.UTC(2010, 10, 15, 16, 23, 10, 113));
// Try to parse
anychart.format.parseDateTime("13:31:16", "HH:mm:ss");
// Returns Date.UTC(2010, 10, 15, 13, 31, 16, 113)

Try it:

inputDateTimeFormat

Getter for the input date time format.

Returns:

string - The date time format.
See listing
var dateTimeFormat = anychart.format.inputDateTimeFormat();
Setter for the input date time format. Has priority over the format of localization.

Params:

Name Type Description
value string Input date time format for parsing

Returns:

string - The date time format.

Try it:

inputLocale

Getter for the input format settings.

Returns:

string anychart.format.Locale - The localization name or settings.
See listing
var currentInputLocale = anychart.format.inputLocale();
Setter for the input format settings.

Params:

Name Type Default Description
value string | anychart.format.Locale
"default"
Localization name or settings.

Returns:

string anychart.format.Locale - The localization name or settings.

Try it:

number

Formats number with given settings.

Params:

Name Type Default Description
number number
Number for formatting.
decimalsCountOrLocal number | anychart.format.NumberLocale | string
2
Desired number of decimals or localization.
decimalPoint string
"."
String to modify the decimal separator.
groupsSeparator string
""
String to separate every three digits.
scale Object | boolean
false
Automatic scaling (divides by factor and substitutes suffix). If pass "true", will be used default scale.
zeroFillDecimals boolean
false
Whether to fill in the remaining decimal places zeros.
scaleSuffixSeparator string
""
Additive between the suffix of scale and the number. Works only with scaling.
useBracketsForNegative boolean
Whether to use brackets for negative value.

Returns:

string - Formatted value.

Try it:

Formats number using object.

Params:

Name Type Description
number number Number for formatting.
object anychart.format.NumberLocale Object with settings.

Returns:

string - Formatted value.

Try it:

outputDateFormat

Getter only current output date format.

Returns:

string - The output date format.
Setter only output date format.

Params:

Name Type Description
value string Date format for parsing.

Try it:

outputDateTimeFormat

Getter for the output date and time format.

Returns:

string - The date time format.
Output date and time format. Has priority over the format of localization.

Params:

Name Type Description
value string Date time format for parsing.

Try it:

outputLocale

Getter for the output format settings.

Returns:

string anychart.format.Locale - The localization name or settings.
See listing
var currentOutputLocale = anychart.format.outputLocale();
Setter for the output format settings.

Params:

Name Type Description
value string | anychart.format.Locale Localization name (from anychart.format#locales) or object of localization for output.

Returns:

string anychart.format.Locale - The localization name or settings.

Try it:

outputTimeFormat

Getter only current output time format.

Returns:

string - The current time format.
Setter only output time format.

Params:

Name Type Description
value string Time format for parsing

Try it:

outputTimezone

Getter for the output offset.

Returns:

number - The output offset.
See listing
var currentOutputTimezone = anychart.format.outputTimezone();
Setter for the output offset.
Adjusts time zone by value in minutes. Indicate minutes WEST of UTC to be used as the constant time zone offset.

Params:

Name Type Default Description
value number
0
Value for adjusting time zone in minutes.

Returns:

number - The output offset.

Try it:

parseDateTime

Parses input value to date.

Params:

Name Type Description
value * Input value.
format string Format to be parsed. If undefined, anychart.format.inputDateTimeFormat is be used.
baseDate Date Date object to hold the parsed date. Used in cases when input value doesn't contain information about a year or a month or else. If parsing is successful this object contains absolutely the same values of date time units as the return value.
NOTE: If not Date, Date.UTC(currentYear, currentMoth) is be used.
locale string | anychart.format.Locale Locale to be used. If not set, anychart.format.inputLocale is be used.

Returns:

Date - Parsed date or null if got wrong input value.

Try it:

parseNumber

Parses value to number according to locale set.

Params:

Name Type Description
value * Value to be parsed.
locale anychart.format.NumberLocale | string Number locale to be used. If not defined, anychart.format.input.numberFormat will be used.

Returns:

number - Parsed value. NaN if value could not be parsed.

Try it:

subs

Formats for string substitution. For example: subs("foo%s hot%s", "bar", "dog") becomes "foobar hotdog".

Params:

Name Type Description
string string The string containing the pattern.
var_args * The items to substitute into the pattern.

Returns:

string - A copy of {@code str} in which each occurrence of {@code %s} has been replaced an argument from {@code var_args}.

Try it:

time

Formats time by pattern.
The same that anychart.format.dateTime but with the anychart.format#outputTimeFormat as default datetime format.

Params:

Name Type Description
date number | Date UTC timestamp or Date object.
timeZone number Adjust with time zone. Indicate minutes WEST of UTC to be used as a constant time zone offset.
locale string | anychart.format.Locale Locale to be used.

Returns:

string - Formatted value.

Try it: