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

namespace anychart.format Improve this Doc

Namespace for format.

Functions Overview

dateTime()Formats date by pattern.
inputDateTimeFormat()Input date time format.
inputLocale()Input format setting to be used.
number()Formats number.
outputDateTimeFormat()Output date time format.
outputLocale()Output format setting to be used.
outputTimezone()Output offset in minutes.
parseDateTime()Parses input value to date.
parseNumber()Parses passed value to number considering locale.
subs()Formats for string substitution.

Typedefs Overview

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

Functions Description

dateTime

Formats date 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:

inputDateTimeFormat

Input date time format. Has more priority than the format of localization.

Params:

Name Type Description
value string Input date time format for parsing

Returns:

string - The current date time format.

Try it:

inputLocale

Input format setting to be used.

Params:

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

Returns:

string anychart.format.Locale - The current 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.

Returns:

string - Formatted value.

Try it:

Formats number using object.

Params:

Name Type Description
number number Number for formatting.
settings Object Object with settings.

Returns:

string - Formatted value.

Try it:

outputDateTimeFormat

Output date time format. Has more priority than the format of localization.

Params:

Name Type Description
value string Date time format for parsing

Returns:

string - The current date time format.

Try it:

outputLocale

Output format setting to be used.

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 current localization name or settings.

Try it:

outputTimezone

Output offset in minutes. Adjusts time zone by passed value in minutes. Indicate minutes WEST of UTC to be used as a constant time zone offset.

Params:

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

Returns:

number - The current value.

Try it:

parseDateTime

Parses input value to date.

Params:

Name Type Description
value * Input value.
format string Format to be parsed. If is undefined, anychart.format.inputDateTimeFormat will be used.
dateHolder Date Date object to hold the parsed date. Used for case if input value doesn't contain information about year or month or something like that. If parsing process ends successfully, this object will contain totally the same values of date time units as return value.
NOTE: If is undefined, Date.UTC(currentYear, currentMoth) will be used.
locale string | anychart.format.Locale Locale to be used. If not set, anychart.format.inputLocale will be used.

Returns:

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

Try it:

parseNumber

Parses passed value to number considering locale.

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: