Search code examples
javascriptangularjsmomentjsangular-moment

momentJS default locale is zh-tw and can't seem to overwrite it


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');

Solution

  • If you are using Angular, usually what works for me is this

    .run(["moment", function(moment){
        moment.locale("en");
    }]);