![]() Use zones: const newYork = moment.tz(" 12:00", "America/New_York") Ĭonst losAngeles = newYork.clone().tz("America/Los_Angeles") Ĭonst london = newYork.clone(). React should go into rollupOptions.external, since it requires a single React instance is run in the application. I'm also wary of the final bundle size of the user's application. moment.locale('fr').format('D MMM YY') //Wrong old versions for global default format Let's say I'm building a library with a few dependencies: react, moment, lodash, and uuid, and I want to distribute this in both ES and UMD format. Moment().format('D MMM YY') // Correct, set default global format With imports import moment from 'moment' or if you want to include all locales: With require let moment = require('moment') The solution that seems to work is: import moment from 'moment' Įnd 2017 / 2018: the anothers answers have too much old code to edit, so here my alternative clean answer: "es" in the above example), even though I was setting it to "fr". In one case, importing all the locale files like above would resort in the last imported locale always being used (i.e. Import "moment/locale/fr" //always use French If you only need to support one language it is a bit simpler: import React from "react" If you wanted another language, you'd have to import the locale and add it to the array. Moment.locale('fr', ) // can pass in 'en', 'fr', or 'es' Calling locale on an instance, sets it for that instance AND returns that instance.Īlso, as Shiv said in the comments, make sure you use "" and not "", otherwise it won't work.Īfter struggling, this worked for me for moment v2.26.0: import React from "react" In summation, calling locale on the global moment sets the locale for all future moment instances, but does not return an instance of moment. You can, however, change just the locale of a specific momentĬonsole.log(march.format('MMMM')) // 'Marzo' Moment.locale('de') // returns the new locale, in this case 'de'Ĭonsole.log(march.format('MMMM')) // 'March' still, since the instance was before the locale was setĬonsole.log(deMarch.format('MMMM')) // 'März' Alternatively, you could do something like var deMoment moment () deMoment.lang ('de') and reuse deMoment instead of moment throughout your script. ![]() ![]() If you format first, the language won't process. Some examples: var march = moment('2017-03')Ĭonsole.log(march.format('MMMM')) // 'March' In the docs, you can create language specific instances of moment by doing that. ![]() You need moment.lang ( WARNING: lang() is deprecated since moment 2.8.0, use locale() instead): moment.lang("de").format('LLL') Īs of v2.8.1, moment.locale('de') sets the localization, but does not return a moment. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |