moment Library

How to use the subset of Moment.js utilities exposed as `_moment`

Namespace exposed in indicators: _moment (alias of moment) Works exactly like Moment.js 2.x, but only the methods listed below are guaranteed to be available.


Global API

Function / Constant
Signature (simplified)
Returns / Purpose

moment()

moment(inp?: MomentInput, strict?: boolean)

Moment instance

moment(inp, format, strict?)

Parse with format

moment(inp, format, lang?, strict?)

Parse with locale

moment.utc

utc(inp?, format?, lang?, strict?)

Moment in UTC

moment.unix

unix(timestamp: number)

UTC Moment from seconds

moment.parseZone

parseZone(inp?, format?, …)

Keep original offset

moment.duration

duration(inp?, unit?)

Duration object

moment.locale

locale(lang?: string | string[])

Get / set active locale

moment.locales

locales()

string[] of loaded locales

moment.localeData

localeData(key?)

Locale object

moment.isMoment

isMoment(obj)

boolean

moment.isDate

isDate(obj)

boolean

moment.isDuration

isDuration(obj)

boolean

moment.min

min(...moments)

Earliest Moment

moment.max

max(...moments)

Latest Moment

moment.now

now()

Unix ms (overridable)

moment.defineLocale

defineLocale(lang, spec)

Add locale

moment.updateLocale

updateLocale(lang, spec)

Patch locale

moment.normalizeUnits

normalizeUnits(unit)

Canonical unit string

moment.relativeTimeThreshold

relativeTimeThreshold(key, limit?)

Get / set threshold

moment.relativeTimeRounding

relativeTimeRounding(fn?)

Get / set rounding fn

moment.calendarFormat

calendarFormat(m, now)

Calendar token

Constants

version, ISO_8601, RFC_2822, defaultFormat, defaultFormatUtc, suppressDeprecationWarnings, deprecationHandler, HTML5_FMT

Metadata & helpers

moment.fn

Prototype holding all instance methods (use through any Moment)


Common Instance Methods

Method
Example
Purpose

format()

m.format('YYYY‑MM‑DD')

String formatting

add() / subtract()

m.add(1, 'day')

Date math

diff()

m.diff(other, 'hours')

Time difference

startOf() / endOf()

m.startOf('day')

Snap to unit

isBefore / isAfter

m.isBefore(other)

Comparison

unix() / valueOf()

m.unix()

Timestamp (seconds / ms)

clone()

m.clone()

Immutable copy

Quick example

Last updated