I'm pulling the momentJS library from a CDN in my Angular app:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
The default locale is supposed to be English ('en'). But for some reason, the default locale in my app is 'zh-tw'. I see that this used to be an issue (see here and here), but it was supposedly fixed.
Even if I set the global locale manually, it is being ignored:
In my index.html file:
<script>
moment.locale('en');
</script>
In my Angular controller:
moment.locale('en');
The only thing that works right now is if I set the locale on each moment instance:
var moment1 = moment(myDate);
moment1.locale('en');
var moment2 = moment(moment1).add(24, 'h');
moment2.locale('en');
Moment. js is a fantastic time & date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size.
You can change moment locale globally like that: import moment from 'moment'; import localization from 'moment/locale/fr'; moment. locale('fr', localization);
updateLocale(localeName, config) to change an existing locale. moment. defineLocale(localeName, config) should only be used for creating a new locale. Save this answer.
Moment. js is a stand-alone open-source JavaScript framework wrapper for date objects that eliminates native JavaScript date objects, which are cumbersome to use. Moment. js makes dates and time easy to display, format, parse, validate, and manipulate using a clean and concise API.
If you are using Angular, usually what works for me is this
.run(["moment", function(moment){
moment.locale("en");
}]);
I'm aware this question was posted last year but it's worth noting the following for any users coming across the zh-tw
formatting issue.
This problem cropped up for me today whilst working with the format method. Luckily there is a more permanent fix to this problem within the last few days.
The issue you're having was originally resolved back in 2013 (approximately) and a subsequent update was released. For whatever reason the problem came back in an update sometime before/around update 2.10.3 and has been an issue since. However, on 2 January 2016 they released an update which has subsequently resolved the problem people were having. Updating to Moment 2.11.0
will resolve the language defaulting to zh-tw
and revert it back to en
by default.
Whilst the accepted answer was the fix at the time I recommend you update to the latest version of Moment as from my perspective it was a bit of hack around to resolve your issue, amongst other reasons.
Visit the following link for all the changes in Moment 2.11.0, the issue you'll be interested in is under ID #2735
.
Moment 2.11.0 - Changelog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With