Moment.js: Localized shorthand for placeholder parts, such as "D", "M", "Y"

54 views Asked by At

In the current version of moment.js, I can localize the general format of a date by, for example, using the following code

moment.localeData(this.$i18n.locale).longDateFormat('L')

It will return for "en" DD/MM/YYYY, for Czech language it will return DD.MM.YYYY. Format-wise, that's ok-ish.

How do I achieve, however, to have moment.js automatically localized also the shorthands for the format (in other languages, the word for "year" doesn't start with "Y", etc.).

The longDateFormat has the following properties and I haven't found the way to internationalize the format shorthands as well:

{
    "LTS": "H:mm:ss",
    "LT": "H:mm",
    "L": "DD.MM.YYYY",
    "LL": "D. MMMM YYYY",
    "LLL": "D. MMMM YYYY H:mm",
    "LLLL": "dddd D. MMMM YYYY H:mm",
    "l": "D. M. YYYY"
}

I was looking into the moment.js object structure and documentation, and I didn't find the sufficient information how to internationalize the shorthand for the date format placeholder,

0

There are 0 answers