Accessing Locale Specific Functionality


Advertisements

Here will see the methods and properties available on currently loaded locale.

Syntax

moment.localeData()

You will observe the following output in the browser when we console moment.localeData() −

Accessing

Example

var localeData = moment.localeData();
var m = localeData.months();
var k = localeData.weekdays();

Output

Accessing Locale

The properties can be accessed using moment.localeData(‘property’). The following methods are available from localeData object −

var localeData = moment.localeData();

var m = localeData.months(moment()); // gets the month as per the moment such as April

var m1 = localeData.monthsShort(moment()); // gets the month name in shortform such as Apr

var k = localeData.weekdays(moment()); // returns the weekday for given moment.such as Monday

var k1 = localeData.weekdaysShort(moment()); // returns shortname for weekday for given moment.such as Mon

You can also use the following methods on localeData object −

localeData.weekdaysMin(aMoment);
localeData.weekdaysParse(minShortOrLongWeekdayString);
localeData.longDateFormat(dateFormat);
localeData.isPM(amPmString);
localeData.meridiem(hours, minutes, isLower);
localeData.calendar(key, aMoment);
localeData.relativeTime(number, withoutSuffix, key, isFuture);
localeData.pastFuture(diff, relTime);
localeData.ordinal(number);
localeData.preparse(str);
localeData.postformat(str);
localeData.week(aMoment);
localeData.invalidDate();
localeData.firstDayOfWeek();
localeData.firstDayOfYear();
momentjs_internationalization.htm
Advertisements