D
D
Danya Kozlovskiy2021-06-30 00:41:49
JavaScript
Danya Kozlovskiy, 2021-06-30 00:41:49

Date format in moment.js depending on locale?

Hello, is it possible in momentjs to change the date format depending on the locale, or how can this be adequately implemented using this library?
For example: for Russian DD.MM for English MM.DD.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergei Erm, 2021-06-30
@Larvis

I can suggest using the format in the object, through a variable (can be global)

var locale = 'en-US'; // Сюда значение получаем любым способом
var momentFormat = {
'en-US' => 'MM/DD/Y',
'ru-RU' => 'DD.MM.YYYY'
}
moment().format(momentFormat[locale]);

Perhaps there is something in the documentation, the text hints at standard functions, but you need to look in detail:
Link to the documentation
Something distant:
Question on stack overflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question