Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get locale format with momentjs

I am trying to recover the date format according to the location. For example, if I use moment.locale('fr') retrieve "DD/MM/YYYY" or retrieve "YYYY/MM/DD" with moment.locale('en'). As you can see, I use MomentJS for my date management.

Is there a MomentJS function to recover the format?

like image 366
Nemtecl Avatar asked Apr 16 '18 07:04

Nemtecl


People also ask

Is MomentJs deprecated?

MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week.

How do I get locale from moments?

If you are changing locales frequently, you may want to know what locale is currently being used. This is as simple as calling moment. locale without any parameters.

How do I change locale globally moments?

You can change moment locale globally like that: import moment from 'moment'; import localization from 'moment/locale/fr'; moment. locale('fr', localization); I hope this helps you.


1 Answers

moment.localeData().longDateFormat('L') // "MM/DD/YYYY"

and

moment.localeData('fr').longDateFormat('L') // "DD/MM/YYYY"

seems better

like image 158
Cyrille Bourgois Avatar answered Nov 23 '22 06:11

Cyrille Bourgois