How to change moment config globally

252 Views Asked by At

i use react-native calendars which config the moment like so:

LocaleConfig.locales["he"] = {
monthNames: [
    "ינואר",
    "פברואר",
    "מרץ",
    "אפריל",
    "מאי",
    "יוני",
    "יולי",
    "אוגוסט",
    "ספטמבר",
    "אוקטובר",
    "נובמבר",
    "דצמבר",
],
monthNamesShort: ["ינו", "פבר", "מרץ", "אפ", "מאי", "יוני", "יולי", "אוג", "ספט", "אוק", "נוב", "דצמ"],
dayNames: ["ראשון", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת"],
dayNamesShort: ["א", "ב", "ג", "ד", "ה", "ו", "ש"],
today: "היום",
 };

LocaleConfig.defaultLocale = "he";

and also i use moment in my components and i want to config the dates like :

moment.updateLocale('he', {
longDateFormat : {
    LT : 'HH:mm',
    LTS : 'HH:mm:ss',
    L : 'DD/MM/YYYY',
    LL : 'D MMMM YYYY',
    LLL : 'D MMMM YYYY HH:mm',
    LLLL : 'dddd D MMMM YYYY HH:mm'
}..........................

my problem i dont know how to decalre it one time and just import it to every component that i need (because i have many component that i need to use it)

the question how i can declare it one time and just import it with one line. because right now i have to put all the long code(that above) in every component

(i build my app with mern react native)

1

There are 1 best solutions below

0
On

If you want to change moment globally then please have a look on "https://www.npmjs.com/package/moment-timezone". Here you will find global timezone set methods.