![]() Use zones: const newYork = moment.tz(" 12:00", "America/New_York") Ĭonst losAngeles = newYork.clone().tz("America/Los_Angeles") Ĭonst london = newYork.clone(). moment.locale('fr').format('D MMM YY') //Wrong old versions for global default 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: 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. With require let moment = require('moment') In the docs, you can create language specific instances of moment by doing that. 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. CodingHamster at 7:48 Add a comment 4 This worked for me. utc () in this case doesn't expect any params. The second moment ().utc (date) is for manipulating the current time ( moment ()) and the date parameter is useless since this. Import "moment/locale/fr" //always use French The first moment.utc (date) is for parsing the date. 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' Some examples: var march = moment('2017-03')Ĭonsole.log(march.format('MMMM')) // 'March' 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 |