Skip to content

DateFormatter

Type class

Handles date and time formatting.

More info: Formatting Date & Time Tutorial on date/time formatting

Sources

DateFormatter can be used (imported) via one of the following packages.

/**
* Import from: "core.ts"
* Use like: am4core.DateFormatter
*/
import * as am4core from "@amcharts/amcharts4/core";

Inheritance

DateFormatter extends BaseObject.

DateFormatter is not extended by any other symbol.

Properties

capitalize

Type booleanDefault true

Should the first letter of the formatted date be capitalized?

dateFormat

Type string | DateTimeFormatOptionsDefault "yyyy-MM-dd"

Date format to use.

If format is not supplied in-line in the string, this setting will be used.

firstDayOfWeek

Type number

First day of the week:

  • 0 - Sunday

  • 1 - Monday

  • 2 - Tuesday Etc.

inputDateFormat

Type stringDefault "yyyy-MM-dd"

Date format to use when parsing dates.

intlLocales

Type string

Locales if you are using date formats in Intl.DateTimeFormatOptions syntax.

language

Type $type.Optional <Language>

A reference to Language object.

months

Type Array <MonthNames>Default [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]

A list of month names.

monthsShort

Type Array <ShortMonthNames>Default [ "Jan", "Feb", "Mar", "Apr", "May(short)", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]

A list of short month names.

sprite

Type $type.Optional <Sprite>

Holds reference to parent Sprite object.

timezone

Type $type.Optional <string>Since 4.10.1

If set, will format date/time in specific time zone.

The value should be named time zone, e.g.:

"America/Vancouver", "Australia/Sydney", "UTC".

timezoneOffset

Type $type.Optional <number>

If set, will apply specific offset in minutes before formatting the date text.

The value is a number of minutes from target time zone to UTC.

E.g. 300 will recalculate Dates in "GMT-5" time zone.

utc

Type boolean

Should formatter use UTC functions?

If UTC is used, all date/time values will be independent on client's time zone.

weekdays

Type Array <Weekdays>Default [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

A list of weekday names.

weekdaysShort

Type Array <ShortWeekdays>Default [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]

A list of short weekday names.

4 inherited items
clonedFrom

Type $type.Optional <this>Inherited from BaseObject

Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.

config

Type objectInherited from BaseObject

Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.

Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.

id

Type $type.Optional <string>Inherited from BaseObject

Sets the user-defined id of the element.

uid

Type stringInherited from BaseObject

Returns object's internal unique ID.

Methods

constructor()

Returns DateFormatter

Constructor

format(source: any,
format?: string | DateTimeFormatOptions,
applyTimezone?: boolean
)

Returns string

Formats the date value according to specified format.

More info: Formatting Date & Time Tutorial on date/time formatting

parse(source: any,
format?: string
)

Returns Date

Parses any input value into Date object.

More info: Formatting Date & Time: parsing dates Tutorial on date/time parsing

5 inherited items
clone(cloneId?: string)

Returns thisInherited from BaseObject

Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.

copyFrom(object: this)

Returns voidInherited from BaseObject

Copies all properties and related data from different element.

dispose()

Returns voidInherited from BaseObject

Destroys this object and all related data.

getCurrentThemes()

Returns ITheme[]Inherited from BaseObject

Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.

isDisposed()

Returns booleanInherited from BaseObject

Returns if this object has been already been disposed.

Events

DateFormatter does not have any events.