DateFormatter

Type class

Handles date and time formatting.

Click here Tutorial on date/time formatting
@todo Better type casting of passed in date?
@todo Quarter support?
@todo When parsing named months make the search case-insensitive
@todo Escape a.m./p.m. properly when used in RegEx

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";

/**
 * --------------------------------------------------------
 * Include via: <script src="core.js"></script>
 * Access items like: am4.DateFormatter
 * --------------------------------------------------------
 */

Inheritance

DateFormatter extends BaseObject.

DateFormatter is not extended by any other symbol.

Properties

capitalize
#

Type boolean

Default true

Should the first letter of the formatted date be capitalized?

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 object

Inherited 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.

dateFormat
#

Type string | DateTimeFormatOptions

Default "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.

id
#

Type $type.Optional < string >

Inherited from BaseObject

Sets the user-defined id of the element.

inputDateFormat
#

Type string

Default "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 >

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

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

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

@since 4.10.1

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.

uid
#

Type string

Inherited from BaseObject

Returns object's internal unique ID.

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.

There are 4 inherited items currently hidden from this list.

Methods

clone(

cloneId?: string

)

#

Returns this

Inherited 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.

constructor()

#

Returns DateFormatter

Constructor

copyFrom(

object: this

)

#

Returns void

Inherited from BaseObject

Copies all properties and related data from different element.

dispose()

#

Returns void

Inherited from BaseObject

Destroys this object and all related data.

format(

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

)

#

Returns string

Formats the date value according to specified format.

Click here Tutorial on date/time formatting

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 boolean

Inherited from BaseObject

Returns if this object has been already been disposed.

parse(

source: any,
format?: string

)

#

Returns Date

Parses any input value into Date object.

Click here Tutorial on date/time parsing

There are 5 inherited items currently hidden from this list.

Events

DateFormatter does not have any events.

Adapters

DateFormatter does not have any adapters.